Skip to main content

Module h1

Module h1 

Source
Expand description

HTTP/1.1 message syntax (RFC 9112): heads, framing, chunked bodies.

A head is decoded whole or not at all: decode_request and decode_response first find the empty line that ends it, within Limits::max_head_bytes, and only then parse, so every proper prefix of a valid head is DecodeError::Incomplete and a head that never ends is DecodeError::TooLarge once the cap’s worth of octets has been searched.

The body’s framing is decided from the head by request_framing and response_framing (RFC 9112 §6.3); a chunked body is decoded step by step by ChunkedDecoder, which hands out slices of the caller’s buffer.

Structs§

ChunkedDecoder
The state of a chunked body decode (RFC 9112 §7.1).
RequestHead
A decoded request head, borrowing from the input.
ResponseHead
A decoded response head, borrowing from the input.

Enums§

Chunk
One step of a chunked body.
Framing
How a message body is delimited (RFC 9112 §6.3).

Functions§

connection_has
Whether the Connection field lists option, ignoring ASCII case (RFC 9110 §7.6.1).
content_length
The value of Content-Length, if present: a list of equal values is one value (RFC 9110 §8.6).
decode_request
Decodes a request head. Returns it and the octets it used, the empty line included; the body, if any, starts there.
decode_response
Decodes a response head. Returns it and the octets it used.
encode_chunk
Writes one chunk: the size in uppercase hex, CRLF, the data, CRLF. Empty data writes nothing, because a zero-size chunk is the last chunk.
encode_last_chunk
Writes the last chunk and the trailer section.
encode_request_head
Writes an HTTP/1.1 request head, the empty line included.
encode_response_head
Writes a response head with version HTTP/1.<minor>, the empty line included.
request_framing
The framing of a request body (RFC 9112 §6.3 rules 3 to 7).
response_framing
The framing of a response body (RFC 9112 §6.3 rules 1 to 7), given the method of the request it answers.