Skip to content

Conversation

@giuscris
Copy link
Member

This pull request refines the handling of HTTP file responses, particularly for range requests and HEAD requests in the FileResponse class. 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:

  • Refactored the logic in prepare() to always set the Accept-Ranges header for GET and HEAD requests, regardless of whether it was previously set.
  • Improved parsing and handling of the Range header by ensuring range logic is only applied to GET requests and that the Content-Length header is set to 0 for unsatisfiable ranges. [1] [2]
  • Moved the logic for setting $this->length = 0 for HEAD requests and empty content to the end of the method, ensuring that content length is always correct for these cases.

File streaming optimization:

  • Updated the file streaming loop to avoid reading more bytes than necessary by adjusting the chunk size to the remaining length, preventing over-reading.

@giuscris giuscris added this to the 2.3.0 milestone Dec 18, 2025
@giuscris giuscris requested a review from Copilot December 18, 2025 21:45
@giuscris giuscris self-assigned this Dec 18, 2025
@giuscris giuscris added the enhancement New feature or request label Dec 18, 2025
Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

@giuscris giuscris marked this pull request as ready for review December 19, 2025 18:47
@giuscris giuscris merged commit 269833e into 2.x Dec 19, 2025
7 checks passed
@giuscris giuscris deleted the fix/range-responses branch December 19, 2025 18:47
@giuscris giuscris added bug Something isn't working and removed enhancement New feature or request labels Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants