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 | #[derive (Debug, Default)] |
21 | pub(crate) struct MessageHead<S> { |
22 | /// HTTP version of the message. |
23 | pub(crate) version: http::Version, |
24 | /// Subject (request line or status line) of Incoming message. |
25 | pub(crate) subject: S, |
26 | /// Headers of the Incoming message. |
27 | pub(crate) headers: http::HeaderMap, |
28 | /// Extensions. |
29 | extensions: http::Extensions, |
30 | } |
31 | |
32 | /// An incoming request message. |
33 | #[cfg (feature = "http1" )] |
34 | pub(crate) type RequestHead = MessageHead<RequestLine>; |
35 | |
36 | #[derive (Debug, Default, PartialEq)] |
37 | #[cfg (feature = "http1" )] |
38 | pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri); |
39 | |
40 | /// An incoming response message. |
41 | #[cfg (all(feature = "http1" , feature = "client" ))] |
42 | pub(crate) type ResponseHead = MessageHead<http::StatusCode>; |
43 | |
44 | #[derive (Debug)] |
45 | #[cfg (feature = "http1" )] |
46 | pub(crate) enum BodyLength { |
47 | /// Content-Length |
48 | Known(u64), |
49 | /// Transfer-Encoding: chunked (if h1) |
50 | Unknown, |
51 | } |
52 | |
53 | /// Status of when a Disaptcher future completes. |
54 | pub(crate) enum Dispatched { |
55 | /// Dispatcher completely shutdown connection. |
56 | Shutdown, |
57 | /// Dispatcher has pending upgrade, and so did not shutdown. |
58 | #[cfg (feature = "http1" )] |
59 | Upgrade(crate::upgrade::Pending), |
60 | } |
61 | |
62 | impl MessageHead<http::StatusCode> { |
63 | fn into_response<B>(self, body: B) -> http::Response<B> { |
64 | let mut res: Response = http::Response::new(body); |
65 | *res.status_mut() = self.subject; |
66 | *res.headers_mut() = self.headers; |
67 | *res.version_mut() = self.version; |
68 | *res.extensions_mut() = self.extensions; |
69 | res |
70 | } |
71 | } |
72 | |