Skip to content

fix: drop the upstream Content-Length when the proxy decompresses the body - #221

Open
safaksm wants to merge 1 commit into
developmentseed:mainfrom
safaksm:fix/decompressed-content-length
Open

safaksm wants to merge 1 commit into
developmentseed:mainfrom
safaksm:fix/decompressed-content-length

Conversation

@safaksm

@safaksm safaksm commented Oct 7, 2026

Copy link
Copy Markdown

The reverse proxy handler reads the upstream body with aread(), which decompresses it, and drops Content-Encoding. It keeps the upstream Content-Length, which is the compressed size. With ENABLE_COMPRESSION=false, a client that sends Accept-Encoding: gzip gets the wrong length on routes no middleware rewrites, like /conformance. Uvicorn then raises h11's LocalProtocolError and cuts the connection. The proxy's default compression hides this because it compresses the body again.

This drops Content-Length with Content-Encoding, so Starlette's Response sets the real length.

The new test fails on main: it gets 38 declared for an 18-byte body. pytest passes (763), and so do the pre-commit hooks.

… body

The handler reads the upstream body with aread(), which decompresses it,
and drops Content-Encoding, but kept the upstream Content-Length: the
length of the compressed body. Starlette's Response keeps a given
Content-Length, so the client was told the wrong length. The handler now
drops it with Content-Encoding, and Response sets the length of the body
it sends.
@github-actions github-actions Bot added the fix label Oct 7, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant