Skip to content

Fix range requests#3105

Closed
viccie30 wants to merge 4 commits intoKludex:mainfrom
viccie30:fix-range-requests
Closed

Fix range requests#3105
viccie30 wants to merge 4 commits intoKludex:mainfrom
viccie30:fix-range-requests

Conversation

@viccie30
Copy link
Contributor

@viccie30 viccie30 commented Jan 12, 2026

Summary

FileResponse does not follow the specification for range requests. The problems are:

  1. Omitting bytes in the value of the Content-Range header when a range request is not satisfiable.
  2. When multiple parts are transferred, the value of the Content-Type header should be multipart/byteranges; boundary=<BOUNDARY> and Content-Range should be unset. FileResponse instead sets the Content-Range header to multipart/byteranges and sends the original Content-Type.
  3. When multiple parts are transferred, all header lines should be separated by CRLFs, not LFs. A final CRLF after the last boundary is allowed, but not required. It is seen as the start of an optional epilogue.

These 3 issues are addressed by the first 3 commits. The last commit lets FileResponse make a copy of the headers before modifying them for a range response. This means that it is possible to use the same FileResponse instance multiple times. Not being able to use a FileResponse multiple times was the original reason I started looking into this, but it is not documented either way and it isn't technically a bug fix because of that, I think.

Open questions:

  • Should FileResponse's constructor strip out a Content-Range header if it is passed in headers?

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Kludex
Copy link
Owner

Kludex commented Feb 14, 2026

I've merged every commit in a separate PR, I think it's clear like this. Thanks for this, once again! :)

@Kludex Kludex closed this Feb 14, 2026
@Kludex
Copy link
Owner

Kludex commented Feb 14, 2026

I've kept you as author on every commit, FYI.

@viccie30
Copy link
Contributor Author

Thank you! They really were separate issues, but they all came up while trying to do one thing, so I filed them as 1 PR originally.

@viccie30 viccie30 deleted the fix-range-requests branch February 14, 2026 13:53
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