Skip to content

Commit

Permalink
[HttpFoundation] Update links for X-Accel-Redirect and fail properly …
Browse files Browse the repository at this point in the history
…when X-Accel-Mapping is missing
  • Loading branch information
nicolas-grekas committed Sep 5, 2024
1 parent 9c375b2 commit 4c7be83
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 4c7be83

Please sign in to comment.