Skip to content

fix(engine): request raw bytes for a ranged download - #5

Merged
troke12 merged 2 commits into
troke12:mainfrom
rigaz29:engine-range-identity
Oct 19, 2026
Merged

troke12 merged 2 commits into
troke12:mainfrom
rigaz29:engine-range-identity

Conversation

@rigaz29

@rigaz29 rigaz29 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Go's transport already leaves out gzip when a Range header 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.
  • An Accept-Encoding set on the download is replaced on ranged transfers: it would ask for exactly the compressed bytes that cannot be written at an offset.
  • The probe is unchanged. It sets identity but lets the download's headers override it, and it only reads the response headers.

Commits

  • c37d66e (Ryan Bagas): the original change, rebased onto current main (after the stream downloader in e830f5d).
  • 479ffd9: review changes. Identity is forced on every ranged request, and the description/README/CHANGELOG are corrected. TestRangeKeepsExplicitEncoding became TestRangeOverridesExplicitEncoding.

Test plan

  • go test ./...
  • TestRangeOverridesExplicitEncoding fails against the previous behaviour (explicit header kept)
  • A ranged download from a server that gzips unasked matches the original bytes

✨ Generated with Claude Code (claude.ai/claude-code) 2.1.303 (claude-opus-5-5)

@troke12 troke12 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Range header 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: gzip is kept on ranged requests, which is exactly the case that writes compressed bytes at a file offset (and TestRangeKeepsExplicitEncoding locks that in). I'd force identity on 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.

rigaz29 and others added 2 commits October 19, 2026 09:21
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)
@troke12
troke12 force-pushed the engine-range-identity branch from 8f2548e to 479ffd9 Compare October 19, 2026 02:22
@troke12

troke12 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Rebased onto current main and applied the review: identity is now forced on every ranged request (explicit Accept-Encoding included), and the description/README/CHANGELOG no longer claim Go would add gzip there. Your commit is kept as-is with you as author; the review changes are a separate commit on top. Thanks!

@troke12
troke12 merged commit a6e80e3 into troke12:main Oct 19, 2026
5 checks passed
@rigaz29
rigaz29 deleted the engine-range-identity branch October 19, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants