Fields
state: State = .start,
header_bytes_owned: bool,
Whether or not header_bytes
is allocated or was provided as a fixed buffer.
header_bytes: field_call,
Either a fixed buffer of len max_header_bytes
or a dynamic buffer that can grow up to max_header_bytes
. Pointers into this buffer are not stable until after a message is complete.
max_header_bytes: usize,
The maximum allowed size of header_bytes
.
next_chunk_length: u64 = 0,
done: bool = false,
Whether this parser is done parsing a complete message. A message is only done when the entire payload has been read.
Functions
fn checkCompleteHead(r: *HeadersParser, allocator: std.mem.Allocator, in: []const u8) CheckCompleteHeadError!u32
Pushes
in
into the parser. Returns the number of bytes consumed by the header….Pushes
in
into the parser. Returns the number of bytes consumed by the header. Any header bytes are appended to theheader_bytes
buffer.This function only uses
allocator
ifr.header_bytes_owned
is true, and may be undefined otherwise.fn findChunkedLen(r: *HeadersParser, bytes: []const u8) u32
Returns the number of bytes consumed by the chunk size. This is always less than…
Returns the number of bytes consumed by the chunk size. This is always less than or equal to
bytes.len
. You should checkr.state == .chunk_data
after this to check if the chunk size has been fully parsed.If the amount returned is less than
bytes.len
, you may assume that the parser is in thechunk_data
state and that the first byte of the chunk is atbytes[result]
.fn findHeadersEnd(r: *HeadersParser, bytes: []const u8) u32
Returns the number of bytes consumed by headers. This is always less than or equ…
Returns the number of bytes consumed by headers. This is always less than or equal to
bytes.len
. You should checkr.state.isContent()
after this to check if the headers are done.If the amount returned is less than
bytes.len
, you may assume that the parser is in a content state and the first byte of content is located atbytes[result]
.fn initDynamic(max: usize) HeadersParser
Initializes the parser with a dynamically growing header buffer of up to
max
b…Initializes the parser with a dynamically growing header buffer of up to
max
bytes.fn isComplete(r: *HeadersParser) bool
Returns whether or not the parser has finished parsing a complete message. A mes…
Returns whether or not the parser has finished parsing a complete message. A message is only complete after the entire body has been read and any trailing headers have been parsed.
fn read(r: *HeadersParser, conn: anytype, buffer: []u8, skip: bool) !usize
Reads the body of the message into
buffer
. Returns the number of bytes placed …Reads the body of the message into
buffer
. Returns the number of bytes placed in the buffer.If
skip
is true, the buffer will be unused and the body will be skipped.See
std.http.Client.BufferedConnection for an example of
conn`.fn reset(r: *HeadersParser) void
Completely resets the parser to it’s initial state. This must be called after a…
Completely resets the parser to it’s initial state. This must be called after a message is complete.