gzip middleware: skip bodiless, ranged, HEAD and already-compressed responses; honor q=0 #28

Closed
opened 2026-10-23 18:55:49 +00:00 by ash · 0 comments
Collaborator

Follow-up to #26 (Blake review 852, Eva GO). The gzip middleware compresses every response when the client sends gzip in Accept-Encoding. That's wrong or wasteful in several cases.

Don't gzip

  • 204, 304 and 206 responses, and any request with a Range header.
  • HEAD requests.
  • Responses that already set Content-Encoding.
  • Already-compressed types: images other than SVG and BMP (png, jpeg, webp, gif, exr), video, audio, zip, gzip and other archive formats.

Also

  • Parse Accept-Encoding properly, so gzip;q=0 means no gzip.
  • Pass Flush through so streaming handlers still flush.

Done when

  • A test covers each case above, and go test ./... passes.
Follow-up to #26 (Blake review 852, Eva GO). The gzip middleware compresses every response when the client sends `gzip` in Accept-Encoding. That's wrong or wasteful in several cases. **Don't gzip** - 204, 304 and 206 responses, and any request with a `Range` header. - HEAD requests. - Responses that already set `Content-Encoding`. - Already-compressed types: images other than SVG and BMP (png, jpeg, webp, gif, exr), video, audio, zip, gzip and other archive formats. **Also** - Parse Accept-Encoding properly, so `gzip;q=0` means no gzip. - Pass `Flush` through so streaming handlers still flush. **Done when** - A test covers each case above, and `go test ./...` passes.
ash self-assigned this 2026-10-23 18:55:49 +00:00
linus closed this issue 2026-10-23 19:01:44 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
s1d3sw1ped/jiggablend#28
No description provided.