Repository navigation
fix(engine): request raw bytes for a ranged download - #5
Conversation
troke12
left a comment
There was a problem hiding this comment.
Harmless hardening, happy to take it with two changes:
- The description's premise isn't quite right: Go's transport already skips adding gzip when a
Rangeheader is set (transport.go, and the same in h2_bundle). The real benefit is only against servers that compress without being asked. Please adjust the description/CHANGELOG. - An explicit user-set
Accept-Encoding: gzipis kept on ranged requests, which is exactly the case that writes compressed bytes at a file offset (andTestRangeKeepsExplicitEncodinglocks that in). I'd forceidentityon every ranged request.
Note for the whole set (#1–#11): thanks a lot for these! They are all branched from 5350f79 independently, so every pair conflicts on CHANGELOG.md and most on download.go. main has also moved (e830f5d adds a stream downloader that touches download.go). Could you rebase onto current main and stack them in this order: #1 → #2 → #10 → #8 → #5/#6/#7/#11? #2, #3 and #10 each add their own pass loop / transferCancel in Start; one shared design would be much easier to merge.
A range response that arrives compressed is not the file. Range requests now send Accept-Encoding: identity unless the download already set that header.
Review changes on top of the previous commit: - An Accept-Encoding set on the download is now replaced on ranged requests too: it asks for exactly the compressed bytes that cannot be written at a chunk's offset. TestRangeKeepsExplicitEncoding locked the old behaviour in and becomes TestRangeOverridesExplicitEncoding. - The comment, README and CHANGELOG no longer say the transport would ask for gzip: Go's transport already leaves it out when a Range is set. The header guards against servers that compress unasked. ✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)
8f2548e to
479ffd9
Compare
|
Rebased onto current |
Summary
Ranged transfer requests send
Accept-Encoding: identity, so the bytes written at each chunk's offset are the file itself. A server that does not support ranges still lets the HTTP client negotiate compression.Behavior
gzipwhen aRangeheader is set, so this does not change what Go asks for by default. It guards against servers that compress a ranged response without being asked.Accept-Encodingset on the download is replaced on ranged transfers: it would ask for exactly the compressed bytes that cannot be written at an offset.identitybut lets the download's headers override it, and it only reads the response headers.Commits
c37d66e(Ryan Bagas): the original change, rebased onto currentmain(after the stream downloader in e830f5d).479ffd9: review changes. Identity is forced on every ranged request, and the description/README/CHANGELOG are corrected.TestRangeKeepsExplicitEncodingbecameTestRangeOverridesExplicitEncoding.Test plan
go test ./...TestRangeOverridesExplicitEncodingfails against the previous behaviour (explicit header kept)✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)