Crate http_wire

Crate http_wire 

Source
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§

request
HTTP request encoding and decoding.
response
HTTP response encoding and decoding.

Enums§

WireError
Errors that can occur during HTTP wire format encoding.

Traits§

WireDecode
Parse raw HTTP bytes to determine message boundaries.
WireEncode
Encode HTTP messages to their wire format bytes.