Repository navigation
Raise ResponseHeaderError when response headers cannot be parsed - #866
Open
draarivpatel-ui wants to merge 2 commits into
Open
draarivpatel-ui wants to merge 2 commits into
draarivpatel-ui wants to merge 2 commits into
Conversation
A malformed header line, such as one without a colon, makes llhttp fail while the response headers are still being read. That error was wrapped in SocketReadError, whose message only said that reading from the socket failed, even though the socket was healthy and the header bytes were the problem. Convert failures raised before the headers are complete into ResponseHeaderError while preserving the parser message and the original backtrace. EOF before the headers are complete keeps its current error. Fixes httprb#674.
The begin/rescue in read_headers! added four lines to a class already at the 100 line cap, failing Metrics/ClassLength in CI. Use a method level rescue like initialize does, inline the single use result variable, and drop the single use finished local in readpartial. Behavior is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a response contains a malformed header line, such as a header without a colon, llhttp reports a parse error while the parser is still reading headers.
Parser#addturns that into anIOError, andread_morethen wraps it inHTTP::SocketReadErrorwitherror reading from socket: .... That message points at the socket even though the socket is healthy and the header bytes are the problem.read_headers!now converts aSocketReadErrorraised before the headers are complete intoHTTP::ResponseHeaderError, preserving the parser message and the original backtrace:EOF before the headers are complete still raises
ResponseHeaderErrorexactly as before, and parse errors after the headers are complete are unchanged.Added a regression test that feeds a response with a
verline instead of a valid header field. It fails withSocketReadErrorbefore the change and passes after it.test/http/connection_test.rb(80 runs) andtest/http/response/parser_test.rbpass.Fixes #674.