Expand description
Serialize and parse HTTP/1.x requests and responses to/from wire format bytes.
This crate provides encoding and decoding for HTTP/1.0 and HTTP/1.1 messages. HTTP/2 and HTTP/3 are not supported.
§Encoding
Use the WireEncode trait to convert HTTP messages to their wire format:
use http_wire::WireEncode;
use http::Request;
use http_body_util::Empty;
use bytes::Bytes;
let request = Request::builder()
.uri("/api/users")
.header("Host", "example.com")
.body(Empty::<Bytes>::new())
.unwrap();
let bytes = request.encode().await.unwrap();§Decoding
Use the WireDecode trait to parse raw bytes and determine message boundaries:
use http_wire::WireDecode;
use http_wire::request::RequestLength;
let raw = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n";
if let Some(length) = RequestLength::decode(raw) {
println!("Complete request: {} bytes", length);
}Modules§
Enums§
- Wire
Error - Errors that can occur during HTTP wire format encoding.
Traits§
- Wire
Decode - Parse raw HTTP bytes to determine message boundaries.
- Wire
Encode - Encode HTTP messages to their wire format bytes.