mirror of
https://github.com/fafhrd91/actix-web
synced 2025-09-01 01:16:59 +02:00
simplify Frame::Message; impl Try for Reply
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
//! Pieces pertaining to the HTTP message protocol.
|
||||
use std::{io, mem};
|
||||
use std::error::Error as StdError;
|
||||
use std::{io, mem, str};
|
||||
use std::convert::Into;
|
||||
|
||||
use cookie;
|
||||
use bytes::Bytes;
|
||||
use http::{Method, StatusCode, Version, Uri, HeaderMap, HttpTryFrom, Error};
|
||||
use http::header::{self, HeaderName, HeaderValue};
|
||||
@@ -78,6 +78,17 @@ impl HttpRequest {
|
||||
self.uri.query()
|
||||
}
|
||||
|
||||
/// Return request cookie.
|
||||
pub fn cookie(&self) -> Result<Option<cookie::Cookie>, cookie::ParseError> {
|
||||
if let Some(val) = self.headers.get(header::COOKIE) {
|
||||
let s = str::from_utf8(val.as_bytes())
|
||||
.map_err(|e| cookie::ParseError::from(e))?;
|
||||
cookie::Cookie::parse(s).map(|c| Some(c))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the Request headers.
|
||||
#[inline]
|
||||
pub fn headers_mut(&mut self) -> &mut HeaderMap {
|
||||
@@ -300,13 +311,7 @@ impl HttpResponse {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Error> for HttpResponse {
|
||||
fn from(err: Error) -> Self {
|
||||
HttpResponse::new(StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Body::Binary(err.description().into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper conversion implementation
|
||||
impl<I: Into<HttpResponse>, E: Into<HttpResponse>> From<Result<I, E>> for HttpResponse {
|
||||
fn from(res: Result<I, E>) -> Self {
|
||||
match res {
|
||||
|
Reference in New Issue
Block a user