Skip to content

gateway: strip Content-Length header when gzip encoding sync response#4054

Open
twmb wants to merge 1 commit intomainfrom
1261
Open

gateway: strip Content-Length header when gzip encoding sync response#4054
twmb wants to merge 1 commit intomainfrom
1261

Conversation

@twmb
Copy link
Contributor

@twmb twmb commented Mar 2, 2026

When the gzip handler compresses a sync_response body, any user-set Content-Length metadata header (computed on the uncompressed payload) becomes incorrect. Override WriteHeader and Write on gzipResponseWriter to delete Content-Length before headers are frozen, letting Go's HTTP server fall back to Transfer-Encoding: chunked.

Fixes #1261

When the gzip handler compresses a sync_response body, any user-set
Content-Length metadata header (computed on the uncompressed payload)
becomes incorrect. Override WriteHeader and Write on gzipResponseWriter
to delete Content-Length before headers are frozen, letting Go's HTTP
server fall back to Transfer-Encoding: chunked.

Fixes #1261

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link

claude bot commented Mar 2, 2026

Claude finished @twmb's task in 1m 19s —— View job


  • Gather context (PR diff, agent guidelines)
  • Validate commit policy
  • Perform code review
  • Post summary

Commits
LGTM

Review
Adds WriteHeader override on gzipResponseWriter to strip the user-set Content-Length (computed on uncompressed data) before headers are frozen, with a defensive deletion in Write for implicit WriteHeader(200) paths. Test covers both gzip and non-gzip cases and validates the header is removed and the body decompresses correctly.

LGTM


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input HTTP server with sync_response, handling of Accept-Encoding: gzip header can give issues

1 participant