Repository navigation
Conversation
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.
Fixes #124.
cb_on_headers_completereturns1whenever theupgradeflag is set. That tells llhttp to skip the body, so an upgrade request that has a body (e.g.Upgrade: h2c+Content-Lengthor chunked, which JDK'sHttpClientandcurl --http2send by default) raisesHttpParserUpgraderight after the headers. The body is lost, and the bytes after the offset are parsed as a new request.llhttp already makes this decision itself in
llhttp__after_headers_complete: it pauses right after the headers for upgrades without a body,CONNECT, and101responses, and otherwise parses the body and pauses afteron_message_complete. Returning0lets it do that.What changes:
on_bodyandon_message_completefirst. ThenHttpParserUpgradeis raised with the offset after the body.GETwith no body),CONNECT, and101responses behave the same as before.This matches the RFCs. A server may ignore
Upgrade(RFC 9110 §7.8), and an h2c upgrade request's body has to be read as HTTP/1.1 before switching protocols (RFC 7540 §3.2).I ran uvicorn's protocol test suite against this branch and it passes. It also fixes Kludex/uvicorn#2722.
AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.