1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 08:57:00 +02:00

use trait instead of pipeline

This commit is contained in:
Nikolay Kim
2017-12-09 04:33:40 -08:00
parent 4a40b026a4
commit b98ab2eebe
15 changed files with 189 additions and 145 deletions

View File

@@ -19,18 +19,17 @@ use error::{ParseError, PayloadError, UrlGenerationError,
MultipartError, CookieParseError, HttpRangeError, UrlencodedError};
struct HttpMessage {
version: Version,
method: Method,
uri: Uri,
headers: HeaderMap,
extensions: Extensions,
params: Params<'static>,
cookies: Option<Vec<Cookie<'static>>>,
addr: Option<SocketAddr>,
payload: Payload,
info: Option<ConnectionInfo<'static>>,
pub struct HttpMessage {
pub version: Version,
pub method: Method,
pub uri: Uri,
pub headers: HeaderMap,
pub extensions: Extensions,
pub params: Params<'static>,
pub cookies: Option<Vec<Cookie<'static>>>,
pub addr: Option<SocketAddr>,
pub payload: Payload,
pub info: Option<ConnectionInfo<'static>>,
}
impl Default for HttpMessage {
@@ -51,6 +50,27 @@ impl Default for HttpMessage {
}
}
impl HttpMessage {
/// Checks if a connection should be kept alive.
pub fn keep_alive(&self) -> bool {
if let Some(conn) = self.headers.get(header::CONNECTION) {
if let Ok(conn) = conn.to_str() {
if self.version == Version::HTTP_10 && conn.contains("keep-alive") {
true
} else {
self.version == Version::HTTP_11 &&
!(conn.contains("close") || conn.contains("upgrade"))
}
} else {
false
}
} else {
self.version != Version::HTTP_10
}
}
}
/// An HTTP Request
pub struct HttpRequest<S=()>(Rc<HttpMessage>, Rc<S>, Option<Router<S>>);
@@ -101,6 +121,10 @@ impl<S> HttpRequest<S> {
unsafe{mem::transmute(r)}
}
pub(crate) fn get_inner(&mut self) -> &mut HttpMessage {
self.as_mut()
}
/// Shared application state
#[inline]
pub fn state(&self) -> &S {