diff --git a/lib/std/http.zig b/lib/std/http.zig index 4ec91d3af5..a9e704ab00 100644 --- a/lib/std/http.zig +++ b/lib/std/http.zig @@ -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 diff --git a/lib/std/http/Server.zig b/lib/std/http/Server.zig index 6cf5748271..be0a3ac09f 100644 --- a/lib/std/http/Server.zig +++ b/lib/std/http/Server.zig @@ -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,