Skip to content

fix(client): parse proxy CONNECT response with httparse - #315

Merged
seanmonstar merged 2 commits into
hyperium:masterfrom
aashish-thapa:fix/tunnel-connect-parse
Aug 28, 2026
Merged

fix(client): parse proxy CONNECT response with httparse#315
seanmonstar merged 2 commits into
hyperium:masterfrom
aashish-thapa:fix/tunnel-connect-parse

Conversation

@aashish-thapa

Copy link
Copy Markdown
Contributor

Closes #4095.

The CONNECT tunnel validated the proxy's response by pattern-matching the buffer instead of parsing it, which caused two problems:

  • Malformed responses were accepted.starts_with(b"HTTP/1.1 200") only checks a prefix, so a status like HTTP/1.1 2000 OK was treated as a successful tunnel.
  • Server-speaks-first responses broke. Success required the whole buffer to end with \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, and Status::Complete locates 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 public Service::Response type. 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.

@aashish-thapa

aashish-thapa commented Aug 23, 2026

Copy link
Copy Markdown
ContributorAuthor

@seanmonstar would you mind reviewing it when you get a chance please.

@seanmonstarseanmonstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@seanmonstar
seanmonstar merged commit d480d9f into hyperium:masterAug 28, 2026
18 checks passed
Sign up for freeto 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

@aashish-thapa@seanmonstar