Skip to content

Commit 4c7be83

Browse files
[HttpFoundation] Update links for X-Accel-Redirect and fail properly when X-Accel-Mapping is missing
1 parent 9c375b2 commit 4c7be83

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)