2 releases
Uses old Rust 2015
0.1.1 | Sep 2, 2018 |
---|---|
0.1.0 | Aug 30, 2018 |
#62 in #clients
Used in tokio-arangodb
15KB
333 lines
http-codec
This crate provides http/1.1 (tokio-)codecs for servers and clients.
Example
extern crate http_codec;
use http_codec::client::HttpCodec;
fn main() {
let mut fake = FakeStream::new();
let res = b"\
HTTP/1.1 200 OK\r\n\
Date: Mon, 27 Jul 2009 12:28:53 GMT\r\n\
Server: Apache/2.2.14 (Win32)\r\n\
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT\r\n\
Content-Length: 9\r\n\
Content-Type: text/html\r\n\r\n\
something";
let wl = fake.write(res).unwrap();
assert_eq!(res.len(), wl);
let mut framed = HttpCodec::new().framed(fake);
let response = match framed.poll().unwrap() {
Async::Ready(Some(response)) => response,
_ => panic!("no response"),
};
assert_eq!(response.status().as_u16(), 200);
assert_eq!(response.headers().len(), 5);
assert_eq!(response.body(), &Bytes::from_static(b"something"));
}
Dependencies
~1.5MB
~25K SLoC