manager: drop stale Content-Length when gzipping (closes #25) #26
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!26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ash/gzip-content-length-25"
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 #25
gzipMiddlewaregzipped the body but kept the handler-setContent-Length(the uncompressed size), so browsers failed with ERR_CONTENT_LENGTH_MISMATCH on preview-exr andcurl --compressedexited 18.gzipResponseWriternow deletesContent-Lengthon the firstWriteHeader, andWritecallsWriteHeader(200)first if the handler didn't, so implicit-header handlers are covered too. Duplicate WriteHeader calls are ignored.Vary: Accept-Encodingwas already set on every compressed response, so that's unchanged.internal/manager/gzip_test.go: a real httptest server with explicit and implicit WriteHeader. It asserts gzip encoding, Vary, no stale Content-Length, a clean read, and that the body decompresses to the original bytes.Proof: without the fix both subtests fail (
stale uncompressed Content-Length 81920 sent with gzipped body). With the fix they pass;go build ./...andgo vetare clean. No other changes: the Go version is untouched.Not in this PR: skipping gzip for already-compressed types (png/zip), which the owner comment mentions. Eva's brief was the minimal fix, so that can be a follow-up if wanted.
GO on
8b0fa615ea. The fix is right where the bug was: dropping Content-Length on the first WriteHeader, and having Write call WriteHeader(200) first, covers handlers that set the header either way. The duplicate-WriteHeader guard is fine. The test uses a real server, checks both paths, and fails without the fix. CI is green and the head sits on the current develop tip.Skipping gzip for already-compressed types can be its own issue if Justin wants it. Linus, it's yours to merge.
GO on head
8b0fa615ea(base develop @3ead2cc, up to date). CI run 47 green (CI / check-and-test).Checked:
WriteHeaderdeletes it; firstWritecallsWriteHeader(200)first; thewroteHeaderguard makes repeat calls no-ops. Flush: the wrapper doesn't implementhttp.Flusher, and nothing ininternal/flushes, so there's no third path. That hasn't changed.Content-Encoding(the middleware is the only setter), so nothing gets gzipped twice. That hasn't changed.gz.Close()writes on bodiless responses is the same as before this PR, and net/http drops it.Non-blocking follow-ups (both were there before this PR): range responses (jobs.go ~3095, 206 + Content-Range) are still gzipped, so Content-Range describes uncompressed bytes. Skipping gzip for Range/206 and for already-compressed types (png/zip/exr), as the issue asked, would fix both.
Blake security GO on
8b0fa615ea.Read the diff myself. It does what #25 asks:
Non-blocking follow-ups. All of these were already there before this PR: