Repository navigation
fix(api): stop gzip middleware from dropping response starts on Starlette 1.8 - #9884
Merged
joshistoast merged 4 commits intoOct 17, 2026
Merged
Conversation
…ette 1.8 Route each response at http.response.start through Starlette's public GZipMiddleware only when its content type compresses; send everything else directly. Starlette 1.8 forwards the start for its own excluded types inside the responder, so the old flag patch lost it for types like font/ttf and application/octet-stream. Lock starlette 1.8.0 so CI runs what pip/launcher installs resolve to.
Pfannkuchensack
requested review from
blessedcoolant,
joshistoast and
lstein
as code owners
October 16, 2026 14:15
joshistoast
approved these changes
Oct 17, 2026
joshistoast
enabled auto-merge (squash)
October 17, 2026 17:38
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.
Summary
Since Starlette 1.8.0 (released 2026-10-13), some responses fail with
RuntimeError: Expected ASGI message 'http.response.start', but got 'http.response.body'. FastAPI 0.141.1 only requiresstarlette>=0.46.0, so pip and launcher installs pick up 1.8.0 even thoughuv.lockpinned 1.7.0.Cause:
_ContentTypeAwareGZipResponderset Starlette's internalcontent_type_is_excludedflag after the base responder had already handledhttp.response.start. Starlette 1.8 now forwards the start inside that branch for the types it excludes itself, and its body branch only sends the body. So for any type that Starlette would compress but our allowlist skips, the start was buffered and never sent. Affected types includefont/ttf/font/otf(user fonts),application/octet-streamandapplication/pdf, for any client that sendsAccept-Encoding: gzip, which every browser does.Fix:
ContentTypeAwareGZipMiddlewareno longer patches Starlette internals. When a response starts, it checks the content type. Compressible responses go through Starlette's publicGZipMiddleware; everything else goes straight to the server. This works the same on every Starlette release FastAPI allows.uv.locknow pins Starlette 1.8.0, so CI runs the version users actually get. Only the starlette entry in the lockfile changed.Related Issues / Discussions
Reported by about five users on Discord after upgrading.
QA Instructions
pytest tests/app/api/test_gzip_content_types.py: 40 passed each on Starlette 1.8.0, 1.7.0 and 0.48.0.font/ttf,application/pdfandapplication/octet-stream, buffered and streamed), withReceived "http.response.body" without "http.response.start".ruff checkandruff format --checkpass on the changed files.uv lock --checkpasses.Manual repro on an affected install: with Starlette 1.8.0,
curl -H 'Accept-Encoding: gzip' http://127.0.0.1:9090/api/v1/utilities/fonts/<font>.ttf(or any otherfont/ttforapplication/octet-streamresponse). This logs the RuntimeError onmainand serves the file with this branch.Workaround for users until this ships:
http_compression_level: 0ininvokeai.yaml, orpip install "starlette==1.7.0".Review
No material findings. Checked: early-hint and other pre-start messages, pathsend, HEAD/206/304, errors raised mid-response together with
ServerErrorMiddleware,Varyand non-gzip clients. Building the middleware per request costs about 3 µs. Responses that are not compressed skip the responder, so they are cheaper than before.Checklist
What's Newcopy (if doing a release after this PR)Need help on this PR? Tag
@codesmith-botwith what you need.