fix(client): parse proxy CONNECT response with httparse - #315
Open
aashish-thapa wants to merge 2 commits into
Open
fix(client): parse proxy CONNECT response with httparse#315aashish-thapa wants to merge 2 commits into
aashish-thapa wants to merge 2 commits into
Conversation
Author
|
@tottoto would you mind reviewing it when you get a chance please. |
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.
Closes #4095.
The CONNECT tunnel validated the proxy's response by pattern-matching the buffer instead of parsing it, which caused two problems:
starts_with(b"HTTP/1.1 200")only checks a prefix, so a status likeHTTP/1.1 2000 OKwas treated as a successful tunnel.\r\n\r\n. When the destination's first bytes arrive in the same read (HTTP/1.1 200 OK\r\n\r\n<data>), that check fails, so the loop keeps reading for a response that already came and stalls until EOF.This parses the response with
httparse(the parser hyper already uses). The status line is validated properly, andStatus::Completelocates the end of the headers even when data trails them, so the tunnel establishes correctly.One thing left out on purpose: the early bytes are now recognized but not yet handed back to the caller. Returning them means replaying the buffered data through something like
Rewind, which changes the publicService::Responsetype. Happy to do that as a follow-up if you want it, but it felt like a separate, breaking decision rather than part of this fix.The first commit adds tests that fail against the current heuristic; the second applies the fix and they pass.