fix: strip content-length from upstream headers in non-streaming response (OQP-1)#5
Merged
Merged
Conversation
…onse (OQP-1) JSONResponse re-serialises the upstream JSON body using compact separators, producing a body that differs from Ollama's trailing-newline-padded bytes. Starlette only auto-computes content-length when the header is absent, so passing upstream headers caused the stale (off-by-one) value to win. Add _STRIP_RESPONSE_HEADERS constant and filter content-length and transfer-encoding before building the JSONResponse. Add regression test that asserts the returned content-length matches the re-serialised body, not the upstream value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
content-lengthandtransfer-encodingfrom upstream headers before passing toJSONResponsein the non-streaming path\nto non-streaming JSON responses;JSONResponsere-serialises without it, producing a body 1 byte shorter than the upstreamcontent-lengthcontent-lengthwhen the header is absent — the stale upstream value was winningRoot cause
dispatch_requestpassedheaders={**dict(resp.headers), ...}directly toJSONResponse. Starlette skips length recomputation ifcontent-lengthis present in the passed headers.Changes
_STRIP_RESPONSE_HEADERS = {"content-length", "transfer-encoding"}module-level constant inproxy.pyJSONResponsetest_non_streaming_response_content_length_correctintests/test_proxy.pyTest plan
\n, assertsContent-Lengthmatches re-serialised body🤖 Co-authored with Claude Sonnet 4.6