GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Parse the request body before raising `HttpParserUpgrade` by Kludex · Pull Request #155 · MagicStack/httptools

Conversation

@Kludex

@Kludex Kludex commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #124.

cb_on_headers_complete returns 1 whenever the upgrade flag is set. That tells llhttp to skip the body, so an upgrade request that has a body (e.g. Upgrade: h2c + Content-Length or chunked, which JDK's HttpClient and curl --http2 send by default) raises HttpParserUpgrade right 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, and 101 responses, and otherwise parses the body and pauses after on_message_complete. Returning 0 lets it do that.

What changes:

  • An upgrade request with a body fires on_body and on_message_complete first. Then HttpParserUpgrade is raised with the offset after the body.
  • WebSocket handshakes (GET with no body), CONNECT, and 101 responses 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Kludex
Parse the request body before raising HttpParserUpgrade
5480c85
Vizonex
Vizonex approved these changes Oct 30, 2026
View reviewed changes

@Vizonex Vizonex left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Decided to review because nobody seems to be available at the moment but this looks good, I hope it's merged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kludex reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

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

Reviewers

1 more reviewer
@Vizonex Vizonex Vizonex approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug report candidate: Uvicorn drops body with Upgrade: h2c + chunked" [Bug] Request body lost when Upgrade: h2c + Transfer-Encoding: chunked is used

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Kludex @Vizonex
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.