-
Notifications
You must be signed in to change notification settings - Fork 14
Fix HTTP Range handling for file responses (RFC 7233–compliance and Safari compatibility) #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…afari compatibility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors HTTP Range request handling in the FileResponse class to improve RFC 7233 compliance and optimize file streaming. The changes restructure the prepare() method to always set the Accept-Ranges header for GET and HEAD requests, move Range header processing logic before HEAD request handling, and optimize the file streaming loop to avoid reading excess bytes.
Key changes:
- Restructured Accept-Ranges header logic to always set it for GET/HEAD requests (if not already present)
- Moved Range header parsing and processing from after HEAD request early-return to a unified block that processes both GET and HEAD requests
- Optimized file streaming to read only the minimum of chunk size or remaining length
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request refines the handling of HTTP file responses, particularly for range requests and HEAD requests in the
FileResponseclass. The changes improve standards compliance and ensure correct header and content length handling for various request scenarios.Improvements to HTTP range and HEAD request handling:
prepare()to always set theAccept-Rangesheader for GET and HEAD requests, regardless of whether it was previously set.Rangeheader by ensuring range logic is only applied to GET requests and that theContent-Lengthheader is set to0for unsatisfiable ranges. [1] [2]$this->length = 0for HEAD requests and empty content to the end of the method, ensuring that content length is always correct for these cases.File streaming optimization: