From 9f9f2300d782f272577d60deed4dd1d208937ca2 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Mon, 16 Feb 2015 14:04:09 -0300 Subject: [PATCH] [2.3] [HttpFoundation] fixed param order for Nginx's x-accel-redirect | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | kinda | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13502 | License | MIT | Doc PR | n/a fixes #13502 Inverted path and location directives for x-accel-redirect header Before: ```proxy_set_header X-Accel-Mapping /internal/=/var/www/example.com/``` After: ```proxy_set_header X-Accel-Mapping /var/www/example.com/=/internal/``` --- src/Symfony/Component/HttpFoundation/BinaryFileResponse.php | 5 +++-- .../HttpFoundation/Tests/BinaryFileResponseTest.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index bcb4d7077bd1..69afbe1c849a 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -194,12 +194,13 @@ public function prepare(Request $request) $path = $this->file->getRealPath(); if (strtolower($type) == 'x-accel-redirect') { // Do X-Accel-Mapping substitutions. + // @link http://wiki.nginx.org/X-accel#X-Accel-Redirect foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) { $mapping = explode('=', $mapping, 2); if (2 == count($mapping)) { - $location = trim($mapping[0]); - $pathPrefix = trim($mapping[1]); + $pathPrefix = trim($mapping[0]); + $location = trim($mapping[1]); if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) { $path = $location.substr($path, strlen($pathPrefix)); diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index 631f25ff1d2f..1d8731c66577 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -222,8 +222,8 @@ public function testAcceptRangeNotOverriden() public function getSampleXAccelMappings() { return array( - array('/var/www/var/www/files/foo.txt', '/files/=/var/www/', '/files/var/www/files/foo.txt'), - array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'), + array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'), + array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'), ); }