Skip to content

CompressHandler: keep Content-Encoding on FileServer errors - #271

Open
team-humaki wants to merge 1 commit into
gorilla:mainfrom
team-humaki:fix-compress-404-content-encoding
Open

team-humaki wants to merge 1 commit into
gorilla:mainfrom
team-humaki:fix-compress-404-content-encoding

Conversation

@team-humaki

Copy link
Copy Markdown

Summary

Go 1.23+ ServeContent/FileServer clears Content-Encoding on error responses. CompressHandler still compresses the body, so clients see garbled 404s without the encoding header.

Re-apply Content-Encoding in WriteHeader/Write when compressing (#259).

Test plan

  • go test ./...
  • New TestCompressHandlerFileServer404KeepsEncoding

Fixes #259

## Summary
Go 1.23+ `ServeContent`/`FileServer` clears `Content-Encoding` on error responses. CompressHandler still compresses the body, so clients see garbled 404s without the encoding header.

Re-apply `Content-Encoding` in `WriteHeader`/`Write` when compressing (gorilla#259).

## Test plan
- [x] `go test ./...`
- [x] New `TestCompressHandlerFileServer404KeepsEncoding`

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CompressHandler if combined with http.Fileserver misses "Content-Encoding: deflate" on 404 status codes

1 participant