Function reader [src]
Prototype
pub fn reader(request: *Request) ReaderError!std.io.AnyReader
Parameters
request: *Request
Possible Errors
File descriptor does not hold the required rights to write to it.
Connection reset by peer.
The client sent an expect HTTP header value other than "100-continue".
The process cannot access the file because another process has locked a portion of the file. Windows-only.
The socket type requires that message be sent atomically, and the size of the message to be sent made this impossible. The message is not transmitted.
This error occurs when a device gets disconnected before or mid-flush while it's being written to - errno(6): No such device or address.
This error occurs in Linux if the process being written to no longer exists.
The Operating System returned an undocumented error code.
This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.
When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.
This error occurs when no global event loop is configured, and reading from the file descriptor would block.
Source
pub fn reader(request: *Request) ReaderError!std.io.AnyReader {
const s = request.server;
assert(s.state == .received_head);
s.state = .receiving_body;
s.next_request_start = request.head_end;
if (request.head.expect) |expect| {
if (mem.eql(u8, expect, "100-continue")) {
try request.server.connection.stream.writeAll("HTTP/1.1 100 Continue\r\n\r\n");
request.head.expect = null;
} else {
return error.HttpExpectationFailed;
}
}
switch (request.head.transfer_encoding) {
.chunked => {
request.reader_state = .{ .chunk_parser = http.ChunkParser.init };
return .{
.readFn = read_chunked,
.context = request,
};
},
.none => {
request.reader_state = .{
.remaining_content_length = request.head.content_length orelse 0,
};
return .{
.readFn = read_cl,
.context = request,
};
},
}
}