manager: skip gzip for bodiless, ranged, HEAD and compressed responses (closes #28) #29
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
blocked
draft
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
s1d3sw1ped/jiggablend!29
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ash/gzip-skip-28"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #28. Follow-up to #26, folding in Blake's review 852.
The middleware now decides per response, in
WriteHeader, whether to compress:Content-Rangeresponse, responses that already setContent-Encoding, and already-compressed types (images other than SVG and BMP, which covers png, jpeg, webp, gif and exr; video; audio; zip, gzip and other archives; woff).Rangerequests, WebSocket upgrades as before.Accept-Encodingis parsed with q values, sogzip;q=0,*;q=0and*, gzip;q=0all mean no gzip.Flush(flushes gzip, then the connection) andUnwrap, for streaming handlers andhttp.ResponseController.Vary: Accept-Encodingis added rather than overwritten.One side effect: the EXR preview from #25 is
image/png, so it is no longer gzipped at all and keeps its realContent-Length. The #26 Content-Length test now uses a tar body.Tests (
internal/manager/gzip_test.go, real HTTP via httptest): each skip case above comes back unencoded and byte-identical, text still compresses and decompresses, a table foracceptsGzip, and a flush test that reads the first gzipped chunk while the handler is still blocked.go test -race ./internal/managerpasses on the jumpbox. Across the whole tree, onlyrunner/encoding's ffmpeg integration test fails there, because the jumpbox has no ffmpeg. CI has it.GO on
71cbc7be7c.This covers everything in #28 and Blake's notes from 852. The skip decision lives in one place (
WriteHeader), Content-Length is dropped only when we actually compress, and q-value parsing handles the*vs explicitgzipcases correctly, includinggzip;q=0, *. The tests go through real HTTP, and the flush test proves the first chunk reaches the client while the handler is still blocked. Head is on the current develop tip and CI run 50 is green.One small thing, not blocking: HEAD and Range requests return before the wrapper, so they don't get
Vary: Accept-Encodingthe way the matching GET does. If you're in here again, it's worth adding there too.Blake is already on as reviewer. Once he's clear, this goes to Linus.
Security GO on
71cbc7be7c(base developbae029e7b1, which is the current tip).I read the whole diff myself and checked each item from #28 and my 852 notes:
*, q=0 / 0.0 (an explicit gzip entry beats*) and bad q values (treated as not acceptable). I found no way to make it panic: it only uses Cut, Split and ParseFloat with no indexing. TestAcceptsGzip covers all of these.Non-blocking nits:
Vary: Accept-Encoding, but wrapped responses always do. A shared cache could keep an identity response and serve it to everyone, which is harmless. Setting Vary in the outer function would make it consistent.