[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/```
This commit is contained in:
Javier Spagnoletti 2015-02-16 14:04:09 -03:00
parent 31bfc9508b
commit 9f9f2300d7
2 changed files with 5 additions and 4 deletions

View File

@ -194,12 +194,13 @@ class BinaryFileResponse extends Response
$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));

View File

@ -222,8 +222,8 @@ class BinaryFileResponseTest extends ResponseTestCase
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'),
);
}