authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-05-02 21:28:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-01 16:35:28-07:00
log4716c0036678cef93388a25401f32f03fb16dbc1
treec9aca9ceedd2bad6d4452d67e2d40b15386a00af
parent9ed20386bbabad2b458fe2f93a0a5a1ed06527cf

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


2 files changed, 10 insertions(+), 4 deletions(-)

lib/std/http.zig+2-1
......@@ -360,7 +360,8 @@ pub const Reader = struct {
360360 /// The stream is available to be used for the first time, or reused.
361361 ready,
362362 received_head,
363 body_none: void,
363 /// The stream goes until the connection is closed.
364 body_none,
364365 body_remaining_content_length: u64,
365366 body_remaining_chunk_len: RemainingChunkLen,
366367 /// The stream would be eligible for another HTTP request, however the
lib/std/http/Server.zig+8-3
......@@ -534,9 +534,14 @@ pub const Request = struct {
534534 const r = &request.server.reader;
535535 if (keep_alive and request.head.keep_alive) switch (r.state) {
536536 .received_head => {
537 const reader_interface = request.reader() catch return false;
538 _ = reader_interface.discardRemaining() catch return false;
539 assert(r.state == .ready);
537 if (request.head.method.requestHasBody()) {
538 assert(request.head.transfer_encoding != .none or request.head.content_length != null);
539 const reader_interface = request.reader() catch return false;
540 _ = reader_interface.discardRemaining() catch return false;
541 assert(r.state == .ready);
542 } else {
543 r.state = .ready;
544 }
540545 return true;
541546 },
542547 .body_remaining_content_length, .body_remaining_chunk_len, .body_none, .ready => return true,