Skip to content

Commit 9f9f230

Browse files
committed
[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/```
1 parent 31bfc95 commit 9f9f230

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,13 @@ public function prepare(Request $request)
194194
$path = $this->file->getRealPath();
195195
if (strtolower($type) == 'x-accel-redirect') {
196196
// Do X-Accel-Mapping substitutions.
197+
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect
197198
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
198199
$mapping = explode('=', $mapping, 2);
199200

200201
if (2 == count($mapping)) {
201-
$location = trim($mapping[0]);
202-
$pathPrefix = trim($mapping[1]);
202+
$pathPrefix = trim($mapping[0]);
203+
$location = trim($mapping[1]);
203204

204205
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
205206
$path = $location.substr($path, strlen($pathPrefix));

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public function testAcceptRangeNotOverriden()
222222
public function getSampleXAccelMappings()
223223
{
224224
return array(
225-
array('/var/www/var/www/files/foo.txt', '/files/=/var/www/', '/files/var/www/files/foo.txt'),
226-
array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'),
225+
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
226+
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
227227
);
228228
}
229229

0 commit comments

Comments
 (0)