Skip to main content

serialize_request

Function serialize_request 

Source
pub fn serialize_request(req: &HttpRequest) -> Vec<u8> ⓘ
Expand description

Serialize a request to bytes: request line (method, percent-encoded path and query, HTTP/1.1), the request’s headers (minus the writer-owned framing ones), an accurate Content-Length, Connection: close, the blank line, then the body — the exact client-side mirror of serialize_response.

Host rides in headers like any other header (HttpRequest has no separate host field): callers building a client request put host in the map and the writer emits it verbatim — it never synthesizes one. path and query are the decoded forms (parse_request’s output); the writer percent-encodes them (RFC 3986 unreserved set, / kept literal in the path), so parse_request(&serialize_request(req)) reconstructs them exactly.