Skip to content

fix: treat all 1xx responses as bodyless, not just 100/102/103 - #930

Open
danish293 wants to merge 1 commit into
nodejs:mainfrom
danish293:res-1xx-no-body
Open

danish293 wants to merge 1 commit into
nodejs:mainfrom
danish293:res-1xx-no-body

Conversation

@danish293

Copy link
Copy Markdown

Framing bug: a 1xx response whose status code is not 100, 101, 102 or 103 has Content-Length and Transfer-Encoding honoured, so the parser reads the start of the next response as the body of the informational one.

llhttp__after_headers_complete decides this by enumerating the informational codes, while llhttp_message_needs_eof a few lines below tests the whole range with status_code / 100 == 1. The two disagree about which responses can carry a body, and RFC 9112 section 6.3 agrees with the second: any 1xx, 204 or 304 response is terminated by the first empty line after the header fields regardless of the header fields present. The llhttp_status enum already carries 110, 111, 112, 113 and 199.

HTTP/1.1 304 Not Modified\r\nContent-Length: 10\r\n\r\n   -> no body, next message parsed
HTTP/1.1 199 Misc Warning\r\nContent-Length: 10\r\n\r\n   -> next 10 bytes parsed as body

On a kept-alive connection everything after that point is desynchronised, and whoever picks the status code also picks how many bytes get swallowed.

Switching the test to status_code / 100 == 1 covers the range and makes the dedicated 100 branch above it redundant. New cases in test/response/connection.md mirror the HTTP 304 with Content-Length and HTTP 304 with Transfer-Encoding pair already there.

This branch has not been deployed

No deployments
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.

1 participant