1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Encoders and decoders for HTTP/1.x messages based on [bytecodec] crate.
//!
//! [bytecodec]: https://crates.io/crates/bytecodec
//!
//! # Examples
//!
//! Encodes a HTTP request message:
//!
//! ```
//! # extern crate bytecodec;
//! # extern crate httpcodec;
//! use bytecodec::Encode;
//! use bytecodec::bytes::BytesEncoder;
//! use bytecodec::io::IoEncodeExt;
//! use httpcodec::{BodyEncoder, HttpVersion, Method, Request, RequestEncoder, RequestTarget};
//!
//! # fn main() {
//! let request = Request::new(
//! Method::new("GET").unwrap(),
//! RequestTarget::new("/foo").unwrap(),
//! HttpVersion::V1_1,
//! b"barbaz",
//! );
//!
//! let mut encoder = RequestEncoder::new(BodyEncoder::new(BytesEncoder::new()));
//! encoder.start_encoding(request).unwrap();
//!
//! let mut buf = Vec::new();
//! encoder.encode_all(&mut buf).unwrap();
//! assert_eq!(buf, "GET /foo HTTP/1.1\r\nContent-Length: 6\r\n\r\nbarbaz".as_bytes());
//! # }
//! ```
//!
//! Decodes a HTTP response message:
//!
//! ```
//! # extern crate bytecodec;
//! # extern crate httpcodec;
//! use bytecodec::bytes::RemainingBytesDecoder;
//! use bytecodec::io::IoDecodeExt;
//! use httpcodec::{BodyDecoder, HttpVersion, ResponseDecoder};
//!
//! # fn main() {
//! let mut decoder =
//! ResponseDecoder::<BodyDecoder<RemainingBytesDecoder>>::default();
//!
//! let input = b"HTTP/1.0 200 OK\r\nContent-Length: 6\r\n\r\nbarbaz";
//! let response = decoder.decode_exact(input.as_ref()).unwrap();
//!
//! assert_eq!(response.http_version(), HttpVersion::V1_0);
//! assert_eq!(response.status_code().as_u16(), 200);
//! assert_eq!(response.reason_phrase().as_str(), "OK");
//! assert_eq!(
//! response.header()
//! .fields()
//! .map(|f| (f.name().to_owned(), f.value().to_owned()))
//! .collect::<Vec<_>>(),
//! vec![("Content-Length".to_owned(), "6".to_owned())]
//! );
//! assert_eq!(response.body(), b"barbaz");
//! # }
//! ```
//!
//! # References
//!
//! - [RFC 7230] Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
//!
//! [RFC 7230]: https://tools.ietf.org/html/rfc7230
extern crate bytecodec;
extern crate trackable;
pub use ;
pub use ;
pub use Method;
pub use DecodeOptions;
pub use ;
pub use RequestTarget;
pub use ;
pub use ;
pub use HttpVersion;