Skip to content

Commit a414c5d

Browse files
committed
bug #58181 [HttpFoundation] Update links for X-Accel-Redirect and fail 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
2 parents b61630e + 4c7be83 commit a414c5d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

BinaryFileResponse.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,12 @@ public function prepare(Request $request)
244244
}
245245
if ('x-accel-redirect' === strtolower($type)) {
246246
// Do X-Accel-Mapping substitutions.
247-
// @link https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect
248-
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
247+
// @link https://github.com/rack/rack/blob/main/lib/rack/sendfile.rb
248+
// @link https://mattbrictson.com/blog/accelerated-rails-downloads
249+
if (!$request->headers->has('X-Accel-Mapping')) {
250+
throw new \LogicException('The "X-Accel-Mapping" header must be set when "X-Sendfile-Type" is set to "X-Accel-Redirect".');
251+
}
252+
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping'), ',=');
249253
foreach ($parts as $part) {
250254
[$pathPrefix, $location] = $part;
251255
if (substr($path, 0, \strlen($pathPrefix)) === $pathPrefix) {

0 commit comments

Comments
 (0)