feat(server): add Transport to on_request
This commit is contained in:
		| @@ -3,13 +3,15 @@ | ||||
| //! These are requests that a `hyper::Server` receives, and include its method, | ||||
| //! target URI, headers, and message body. | ||||
|  | ||||
| use std::fmt; | ||||
|  | ||||
| use version::HttpVersion; | ||||
| use method::Method; | ||||
| use header::Headers; | ||||
| use http::{RequestHead, MessageHead, RequestLine}; | ||||
| use uri::RequestUri; | ||||
|  | ||||
| pub fn new(incoming: RequestHead) -> Request { | ||||
| pub fn new<'a, T>(incoming: RequestHead, transport: &'a T) -> Request<'a, T> { | ||||
|     let MessageHead { version, subject: RequestLine(method, uri), headers } = incoming; | ||||
|     debug!("Request Line: {:?} {:?} {:?}", method, uri, version); | ||||
|     debug!("{:#?}", headers); | ||||
| @@ -19,22 +21,31 @@ pub fn new(incoming: RequestHead) -> Request { | ||||
|         uri: uri, | ||||
|         headers: headers, | ||||
|         version: version, | ||||
|         transport: transport, | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// A request bundles several parts of an incoming `NetworkStream`, given to a `Handler`. | ||||
| #[derive(Debug)] | ||||
| pub struct Request { | ||||
|     // The IP address of the remote connection. | ||||
|     //remote_addr: SocketAddr, | ||||
| pub struct Request<'a, T: 'a> { | ||||
|     method: Method, | ||||
|     headers: Headers, | ||||
|     uri: RequestUri, | ||||
|     version: HttpVersion, | ||||
|     headers: Headers, | ||||
|     transport: &'a T, | ||||
| } | ||||
|  | ||||
| impl<'a, T> fmt::Debug for Request<'a, T> { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         f.debug_struct("Request") | ||||
|             .field("method", &self.method) | ||||
|             .field("uri", &self.uri) | ||||
|             .field("version", &self.version) | ||||
|             .field("headers", &self.headers) | ||||
|             .finish() | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Request { | ||||
| impl<'a, T> Request<'a, T> { | ||||
|     /// The `Method`, such as `Get`, `Post`, etc. | ||||
|     #[inline] | ||||
|     pub fn method(&self) -> &Method { &self.method } | ||||
| @@ -43,6 +54,10 @@ impl Request { | ||||
|     #[inline] | ||||
|     pub fn headers(&self) -> &Headers { &self.headers } | ||||
|  | ||||
|     /// The underlying `Transport` of this request. | ||||
|     #[inline] | ||||
|     pub fn transport(&self) -> &'a T { self.transport } | ||||
|  | ||||
|     /// The target request-uri for this request. | ||||
|     #[inline] | ||||
|     pub fn uri(&self) -> &RequestUri { &self.uri } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user