Skip to content

Commit

Permalink
[2.3] [HttpFoundation] fixed param order for Nginx's x-accel-redirect
Browse files Browse the repository at this point in the history
| 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/```
  • Loading branch information
phansys committed Feb 16, 2015
1 parent 31bfc95 commit 9f9f230
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
Expand Up @@ -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));
Expand Down
Expand Up @@ -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'),
);
}

Expand Down

0 comments on commit 9f9f230

Please sign in to comment.