| 1 | //! Pieces pertaining to the HTTP message protocol. |
| 2 | |
| 3 | cfg_feature! { |
| 4 | #![feature = "http1" ] |
| 5 | |
| 6 | pub(crate) mod h1; |
| 7 | |
| 8 | pub(crate) use self::h1::Conn; |
| 9 | |
| 10 | #[cfg (feature = "client" )] |
| 11 | pub(crate) use self::h1::dispatch; |
| 12 | #[cfg (feature = "server" )] |
| 13 | pub(crate) use self::h1::ServerTransaction; |
| 14 | } |
| 15 | |
| 16 | #[cfg (feature = "http2" )] |
| 17 | pub(crate) mod h2; |
| 18 | |
| 19 | /// An Incoming Message head. Includes request/status line, and headers. |
| 20 | #[cfg (feature = "http1" )] |
| 21 | #[derive (Debug, Default)] |
| 22 | pub(crate) struct MessageHead<S> { |
| 23 | /// HTTP version of the message. |
| 24 | pub(crate) version: http::Version, |
| 25 | /// Subject (request line or status line) of Incoming message. |
| 26 | pub(crate) subject: S, |
| 27 | /// Headers of the Incoming message. |
| 28 | pub(crate) headers: http::HeaderMap, |
| 29 | /// Extensions. |
| 30 | extensions: http::Extensions, |
| 31 | } |
| 32 | |
| 33 | /// An incoming request message. |
| 34 | #[cfg (feature = "http1" )] |
| 35 | pub(crate) type RequestHead = MessageHead<RequestLine>; |
| 36 | |
| 37 | #[derive (Debug, Default, PartialEq)] |
| 38 | #[cfg (feature = "http1" )] |
| 39 | pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri); |
| 40 | |
| 41 | /// An incoming response message. |
| 42 | #[cfg (all(feature = "http1" , feature = "client" ))] |
| 43 | pub(crate) type ResponseHead = MessageHead<http::StatusCode>; |
| 44 | |
| 45 | #[derive (Debug)] |
| 46 | #[cfg (feature = "http1" )] |
| 47 | pub(crate) enum BodyLength { |
| 48 | /// Content-Length |
| 49 | Known(u64), |
| 50 | /// Transfer-Encoding: chunked (if h1) |
| 51 | Unknown, |
| 52 | } |
| 53 | |
| 54 | /// Status of when a Dispatcher future completes. |
| 55 | pub(crate) enum Dispatched { |
| 56 | /// Dispatcher completely shutdown connection. |
| 57 | Shutdown, |
| 58 | /// Dispatcher has pending upgrade, and so did not shutdown. |
| 59 | #[cfg (feature = "http1" )] |
| 60 | Upgrade(crate::upgrade::Pending), |
| 61 | } |
| 62 | |
| 63 | #[cfg (all(feature = "client" , feature = "http1" ))] |
| 64 | impl MessageHead<http::StatusCode> { |
| 65 | fn into_response<B>(self, body: B) -> http::Response<B> { |
| 66 | let mut res: Response = http::Response::new(body); |
| 67 | *res.status_mut() = self.subject; |
| 68 | *res.headers_mut() = self.headers; |
| 69 | *res.version_mut() = self.version; |
| 70 | *res.extensions_mut() = self.extensions; |
| 71 | res |
| 72 | } |
| 73 | } |
| 74 | |