receiveHead
Buffers the entire head inside in.
The resulting memory is invalidated by any subsequent consumption of the input stream.
Function parameters
Parameters
- reader:*Reader
Type definitions in this namespace
Types
- Method
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
- Status
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
- TransferEncoding
- compression is intentionally omitted here since it is handled in `ContentEncoding`.
- BodyWriter
- Request or response body.
Source
Implementation
pub fn receiveHead(reader: *Reader) HeadError![]const u8 {
reader.trailers = &.{};
const in = reader.in;
const max_head_len = reader.max_head_len;
var hp: HeadParser = .{};
var head_len: usize = 0;
while (true) {
if (head_len >= max_head_len) return error.HttpHeadersOversize;
const remaining = in.buffered()[head_len..];
if (remaining.len == 0) {
in.fillMore() catch |err| switch (err) {
error.EndOfStream => switch (head_len) {
0 => return error.HttpConnectionClosing,
else => return error.HttpRequestTruncated,
},
error.ReadFailed => return error.ReadFailed,
};
continue;
}
head_len += hp.feed(remaining);
if (hp.state == .finished) {
reader.state = .received_head;
const head_buffer = in.buffered()[0..head_len];
in.toss(head_len);
return head_buffer;
}
}
}