Skip to content

report error on unexpected EOF for fixed length HTTP body#427

Merged
Guest0x0 merged 1 commit into
mainfrom
fix-http-parser-eof-handling
Jun 11, 2026
Merged

report error on unexpected EOF for fixed length HTTP body#427
Guest0x0 merged 1 commit into
mainfrom
fix-http-parser-eof-handling

Conversation

@Guest0x0

Copy link
Copy Markdown
Collaborator

Previously, the HTTP body parser does not perform length validation for fixed length body (i.e. Content-Length), this will result in unexpected EOF from the transport layer not being reported as error. This PR fixes the issue. The HTTP body will now raise @io.ReaderClosed on unexpected EOF for fixed length body.

The fix reveal another bug in previous code base. For HEAD request, the response body is always empty, but Content-Length etc. can still be set to indicate what the client would get if a GET request is made. So for response to HEAD request, we should ignore Content-Length etc., but this logic was not implemented previously. Due to the lack of length validation, test for this behavior accidentally passed. This PR also fixes this problem: the response body to a HEAD request is now always assumed to be empty, no matter what headers are set.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 502

Coverage increased (+0.04%) to 77.566%

Details

  • Coverage increased (+0.04%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/internal/event_loop/network.mbt 1 86.36%

Coverage Stats

Coverage Status
Relevant Lines: 4676
Covered Lines: 3627
Line Coverage: 77.57%
Coverage Strength: 72158.55 hits per line

💛 - Coveralls

@Guest0x0 Guest0x0 merged commit ecbb24d into main Jun 11, 2026
17 checks passed
@Guest0x0 Guest0x0 deleted the fix-http-parser-eof-handling branch June 11, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants