| ... | @@ -443,7 +443,7 @@ pub const Reader = struct { | ... | @@ -443,7 +443,7 @@ pub const Reader = struct { |
| 443 | }, | 443 | }, |
| 444 | .none => { | 444 | .none => { |
| 445 | if (content_length) |len| { | 445 | if (content_length) |len| { |
| 446 | reader.state = .{ .body_remaining_content_length = len }; | 446 | reader.state = if (len == 0) .ready else .{ .body_remaining_content_length = len }; |
| 447 | reader.interface = .{ | 447 | reader.interface = .{ |
| 448 | .buffer = transfer_buffer, | 448 | .buffer = transfer_buffer, |
| 449 | .seek = 0, | 449 | .seek = 0, |
| ... | @@ -509,27 +509,29 @@ pub const Reader = struct { | ... | @@ -509,27 +509,29 @@ pub const Reader = struct { |
| 509 | limit: std.Io.Limit, | 509 | limit: std.Io.Limit, |
| 510 | ) std.Io.Reader.StreamError!usize { | 510 | ) std.Io.Reader.StreamError!usize { |
| 511 | const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r)); | 511 | const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r)); |
| | 512 | if (reader.state == .ready) return error.EndOfStream; |
| 512 | const remaining_content_length = &reader.state.body_remaining_content_length; | 513 | const remaining_content_length = &reader.state.body_remaining_content_length; |
| 513 | const remaining = remaining_content_length.*; | 514 | const remaining = remaining_content_length.*; |
| 514 | if (remaining == 0) { | 515 | const n = try reader.in.stream(w, limit.min(.limited64(remaining))); |
| | 516 | if (n == remaining) { |
| 515 | reader.state = .ready; | 517 | reader.state = .ready; |
| 516 | return error.EndOfStream; | 518 | } else { |
| | 519 | remaining_content_length.* = remaining - n; |
| 517 | } | 520 | } |
| 518 | const n = try reader.in.stream(w, limit.min(.limited64(remaining))); | | |
| 519 | remaining_content_length.* = remaining - n; | | |
| 520 | return n; | 521 | return n; |
| 521 | } | 522 | } |
| 522 | | 523 | |
| 523 | fn contentLengthDiscard(io_r: *std.Io.Reader, limit: std.Io.Limit) std.Io.Reader.Error!usize { | 524 | fn contentLengthDiscard(io_r: *std.Io.Reader, limit: std.Io.Limit) std.Io.Reader.Error!usize { |
| 524 | const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r)); | 525 | const reader: *Reader = @alignCast(@fieldParentPtr("interface", io_r)); |
| | 526 | if (reader.state == .ready) return error.EndOfStream; |
| 525 | const remaining_content_length = &reader.state.body_remaining_content_length; | 527 | const remaining_content_length = &reader.state.body_remaining_content_length; |
| 526 | const remaining = remaining_content_length.*; | 528 | const remaining = remaining_content_length.*; |
| 527 | if (remaining == 0) { | 529 | const n = try reader.in.discard(limit.min(.limited64(remaining))); |
| | 530 | if (n == remaining) { |
| 528 | reader.state = .ready; | 531 | reader.state = .ready; |
| 529 | return error.EndOfStream; | 532 | } else { |
| | 533 | remaining_content_length.* = remaining - n; |
| 530 | } | 534 | } |
| 531 | const n = try reader.in.discard(limit.min(.limited64(remaining))); | | |
| 532 | remaining_content_length.* = remaining - n; | | |
| 533 | return n; | 535 | return n; |
| 534 | } | 536 | } |
| 535 | | 537 | |