Function receiveHead [src]
Buffers the entire head inside in.
The resulting memory is invalidated by any subsequent consumption of
the input stream.
Prototype
pub fn receiveHead(reader: *Reader) HeadError![]const u8 Parameters
reader: *Reader Possible Errors
The client sent 0 bytes of headers before closing the stream. This happens when a keep-alive connection is finally closed.
Too many bytes of HTTP headers.
The HTTP specification suggests to respond with a 431 status code before closing the connection.
Partial HTTP request was received but the connection was closed before fully receiving the headers.
Transitive error occurred reading from in.
Source
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;
}
}
}