fix: HTTP Range support on /filedownload#154
Merged
Merged
Conversation
Rocket's FileServer returns 200 + full body for every request, so browsers disable the resume button on interrupted multi-GB downloads. Replace the FileServer mount with a custom range-aware handler that advertises Accept-Ranges, parses single-range Range headers (bytes=N-M, bytes=N-, bytes=-N), and returns 206 + Content-Range for the requested slice. Invalid ranges return 416 with bytes */N. Closes #153
rubenhensen
approved these changes
May 13, 2026
This was referenced May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #153
What changed
Rocket 0.5's
FileServerignores inboundRangeheaders — every request gets a plain 200 with the full body and noAccept-Ranges. Browsers detect that and disable the resume button, so a flaky link on a multi-GB download means restarting from byte 0.Replaces the
FileServermount with a customGET /filedownload/<filename>route that:.., path separators, NUL).Accept-Ranges: bytes.Rangeheader: 200 +Content-Length+ full body.Rangeheader (bytes=N-M,bytes=N-, orbytes=-N): seeks, streams the slice, returns 206 +Content-Range: bytes start-end/total.Content-Range: bytes */total.multipart/byterangesisn't worth the complexity.Also adds
Rangeto the CORSallowed_headerslist so browsers can send it via fetch.Tests
bytes=10-19,bytes=80-,bytes=-5, unsatisfiable → 416, missing file → 404, and a path-traversal attempt → 404.cargo fmt --all -- --check,cargo test(77 passed, +19 vs. main), andcargo clippy --all-targets -- -D warningsall green locally.Out of scope
Client-side resume UX is tracked on the website side at encryption4all/postguard-website#138.
Reviewer quickstart