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 {...@@ -360,7 +360,8 @@ pub const Reader = struct {
360 /// The stream is available to be used for the first time, or reused.360 /// The stream is available to be used for the first time, or reused.
361 ready,361 ready,
362 received_head,362 received_head,
363 body_none: void,363 /// The stream goes until the connection is closed.
364 body_none,
364 body_remaining_content_length: u64,365 body_remaining_content_length: u64,
365 body_remaining_chunk_len: RemainingChunkLen,366 body_remaining_chunk_len: RemainingChunkLen,
366 /// The stream would be eligible for another HTTP request, however the367 /// 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 {...@@ -534,9 +534,14 @@ pub const Request = struct {
534 const r = &request.server.reader;534 const r = &request.server.reader;
535 if (keep_alive and request.head.keep_alive) switch (r.state) {535 if (keep_alive and request.head.keep_alive) switch (r.state) {
536 .received_head => {536 .received_head => {
537 const reader_interface = request.reader() catch return false;537 if (request.head.method.requestHasBody()) {
538 _ = reader_interface.discardRemaining() catch return false;538 assert(request.head.transfer_encoding != .none or request.head.content_length != null);
539 assert(r.state == .ready);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 }
540 return true;545 return true;
541 },546 },
542 .body_remaining_content_length, .body_remaining_chunk_len, .body_none, .ready => return true,547 .body_remaining_content_length, .body_remaining_chunk_len, .body_none, .ready => return true,