Skip to content

Commit

Permalink
bug #58181 [HttpFoundation] Update links for X-Accel-Redirect and f…
Browse files Browse the repository at this point in the history
…ail properly when `X-Accel-Mapping` is missing (nicolas-grekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[HttpFoundation] Update links for `X-Accel-Redirect` and fail properly when `X-Accel-Mapping` is missing

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

The current link is dead and the failure is currently a notice. Let's make this fail properly instead. /cc `@dunglas` ;)

Commits
-------

bfc490d7d8 [HttpFoundation] Update links for X-Accel-Redirect and fail properly when X-Accel-Mapping is missing
  • Loading branch information
fabpot committed Sep 13, 2024
2 parents b61630e + 4c7be83 commit a414c5d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions BinaryFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ public function prepare(Request $request)
}
if ('x-accel-redirect' === strtolower($type)) {
// Do X-Accel-Mapping substitutions.
// @link https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
// @link https://github.com/rack/rack/blob/main/lib/rack/sendfile.rb
// @link https://mattbrictson.com/blog/accelerated-rails-downloads
if (!$request->headers->has('X-Accel-Mapping')) {
throw new \LogicException('The "X-Accel-Mapping" header must be set when "X-Sendfile-Type" is set to "X-Accel-Redirect".');
}
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping'), ',=');
foreach ($parts as $part) {
[$pathPrefix, $location] = $part;
if (substr($path, 0, \strlen($pathPrefix)) === $pathPrefix) {
Expand Down

0 comments on commit a414c5d

Please sign in to comment.