std.http.Server: don't try to discard nonexistent body

This commit is contained in:
Andrew Kelley 2025-05-02 21:28:04 -07:00
parent 9ed20386bb
commit 4716c00366
2 changed files with 10 additions and 4 deletions

View File

@ -360,7 +360,8 @@ pub const Reader = struct {
/// The stream is available to be used for the first time, or reused.
ready,
received_head,
body_none: void,
/// The stream goes until the connection is closed.
body_none,
body_remaining_content_length: u64,
body_remaining_chunk_len: RemainingChunkLen,
/// The stream would be eligible for another HTTP request, however the

View File

@ -534,9 +534,14 @@ pub const Request = struct {
const r = &request.server.reader;
if (keep_alive and request.head.keep_alive) switch (r.state) {
.received_head => {
const reader_interface = request.reader() catch return false;
_ = reader_interface.discardRemaining() catch return false;
assert(r.state == .ready);
if (request.head.method.requestHasBody()) {
assert(request.head.transfer_encoding != .none or request.head.content_length != null);
const reader_interface = request.reader() catch return false;
_ = reader_interface.discardRemaining() catch return false;
assert(r.state == .ready);
} else {
r.state = .ready;
}
return true;
},
.body_remaining_content_length, .body_remaining_chunk_len, .body_none, .ready => return true,