This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function
fndiscardBody(request: *Request, keep_alive: bool) bool {
// Prepare to receive another request on the same connection.// There are two factors to consider:// * Any body the client sent must be discarded.// * The Server's read_buffer may already have some bytes in it from// whatever came after the head, which may be the next HTTP request// or the request body.// If the connection won't be kept alive, then none of this matters// because the connection will be severed after the response is sent.constr = &request.server.reader;
if (keep_aliveandrequest.head.keep_alive) switch (r.state) {
.received_head => {
if (request.head.method.requestHasBody()) {
assert(request.head.transfer_encoding != .noneorrequest.head.content_length != null);
constreader_interface = request.readerExpectContinue(&.{}) catchreturnfalse;
_ = reader_interface.discardRemaining() catchreturnfalse;
assert(r.state == .ready);
} else {
r.state = .ready;
}
returntrue;
},
.body_remaining_content_length, .body_remaining_chunk_len, .body_none, .ready => returntrue,
else => unreachable,
};
// Avoid clobbering the state in case a reading stream already exists.switch (r.state) {
.received_head => r.state = .closing,
else => {},
}
returnfalse;
}
Returns whether the connection should remain persistent.
If it would fail, it instead sets the Server state to receiving body and returns false.