Skip to content

fix: clear stale Content-Encoding and Content-Length after manual gzip decode - #919

Closed
Bolt4243 wants to merge 1 commit into
gocolly:masterfrom
Bolt4243:fix/manual-gzip-stale-headers
Closed

Bolt4243 wants to merge 1 commit into
gocolly:masterfrom
Bolt4243:fix/manual-gzip-stale-headers

Conversation

@Bolt4243

Copy link
Copy Markdown

Fixes #918

Problem

When colly manually gzip-decodes a response body, it left the original Content-Encoding: gzip and the compressed Content-Length on the stored Response. The headers then lied about the now-plaintext body, and Content-Length no longer matched len(Response.Body). Go's transport strips both headers when it transparently decompresses, but colly's manual path did not.

Fix

After a successful manual gzip decode, delete Content-Encoding and Content-Length from the stored response headers, mirroring net/http.

Tests

Added TestManualGzipDecodeClearsStaleHeaders: an httptest server returns a gzip body with Content-Encoding: gzip and a compressed Content-Length; the request sets Accept-Encoding: gzip to force the manual decode path. The test asserts the body is decompressed and that both Content-Encoding and Content-Length are absent on the colly Response. Verified it fails on master and passes with the fix; full suite is green.

…p decode

When colly manually gzip-decodes a response body, it left the original
Content-Encoding: gzip and the compressed Content-Length on the stored
Response, so the headers described a body that no longer matched.

Delete Content-Encoding and Content-Length after a successful manual
gzip decode, mirroring what net/http does when it transparently
decompresses a response.
@WGH- WGH- closed this Jul 25, 2026
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.

Manual gzip decode leaves stale Content-Encoding and Content-Length headers

2 participants