fix(token-spy): rebuild headers for decoded responses - #2971
Open
tang-vu wants to merge 1 commit into
Open
Conversation
This was referenced Aug 22, 2026
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.
Why this matters
Token Spy returns
resp.content, which HTTPX automatically decompresses, but copied the upstream headers unchanged. A gzip response therefore reached clients as decoded bytes still labeledContent-Encoding: gzipand with the compressedContent-Length; real HTTPX clients fail withDecodingError, and other clients can truncate or double-decode the payload.Root cause: representation and hop-by-hop headers were reused after the response representation had changed. HTTPX documents that
Response.contentautomatically decodes gzip/deflate while raw streaming is required to preserve wire encoding: https://www.python-httpx.org/quickstart/#binary-response-contentBehavioral invariant: buffered proxy responses describe the body actually sent downstream, while safe end-to-end metadata remains intact.
Overlap check
Searched open and closed upstream PRs for Token Spy content-encoding/content-length/decoded-response/header passthrough terms and inspected current PRs touching
ods/extensions/services/token-spy/main.py. Existing changes cover streaming status/error logging, SSE cursors, pricing, persistence, and request auth; none rebuild response headers after HTTPX decoding. This scope is independent.What changed
Content-Encoding/Content-Lengthand standard hop-by-hop fields.Validation
DecodingError.pytest tests/test_decoded_response_headers.py -q— 3 passed.pytest tests -q— 23 passed, 1 skipped.python -m py_compile main.py tests/test_decoded_response_headers.py— passed.git diff --check— passed.Tradeoffs and rollback
This keeps buffered proxy behavior; it does not convert large non-streaming responses to raw streaming. Headers tied to a specific hop or encoded wire body are intentionally not forwarded. Rollback is one commit with no persisted-state impact.
Batch compatibility
Validated as an independent ten-PR batch from upstream
main6ff9b4fc5190099705043acaab7e9b6ad9c8b8f1. The final PR heads merged without conflicts in this order: #2964 -> #2965 -> #2967 -> #2969 -> #2970 -> #2971 -> #2972 -> #2973 -> #2974 -> #2975. The resulting local synthetic merge head is4ae60eadad9696a9accb735aad71af87d2be802d.Combined validation on that exact tree:
git diff --check: passed.The scopes are behaviorally independent. The stated order is the tested rollback/merge sequence for shared-file changes; each PR remains individually useful and revertible.