[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:
parent
31bfc9508b
commit
9f9f2300d7
@ -194,12 +194,13 @@ class BinaryFileResponse extends Response
|
|||||||
$path = $this->file->getRealPath();
|
$path = $this->file->getRealPath();
|
||||||
if (strtolower($type) == 'x-accel-redirect') {
|
if (strtolower($type) == 'x-accel-redirect') {
|
||||||
// Do X-Accel-Mapping substitutions.
|
// 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) {
|
foreach (explode(',', $request->headers->get('X-Accel-Mapping', '')) as $mapping) {
|
||||||
$mapping = explode('=', $mapping, 2);
|
$mapping = explode('=', $mapping, 2);
|
||||||
|
|
||||||
if (2 == count($mapping)) {
|
if (2 == count($mapping)) {
|
||||||
$location = trim($mapping[0]);
|
$pathPrefix = trim($mapping[0]);
|
||||||
$pathPrefix = trim($mapping[1]);
|
$location = trim($mapping[1]);
|
||||||
|
|
||||||
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
|
if (substr($path, 0, strlen($pathPrefix)) == $pathPrefix) {
|
||||||
$path = $location.substr($path, strlen($pathPrefix));
|
$path = $location.substr($path, strlen($pathPrefix));
|
||||||
|
@ -222,8 +222,8 @@ class BinaryFileResponseTest extends ResponseTestCase
|
|||||||
public function getSampleXAccelMappings()
|
public function getSampleXAccelMappings()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('/var/www/var/www/files/foo.txt', '/files/=/var/www/', '/files/var/www/files/foo.txt'),
|
array('/var/www/var/www/files/foo.txt', '/var/www/=/files/', '/files/var/www/files/foo.txt'),
|
||||||
array('/home/foo/bar.txt', '/files/=/var/www/,/baz/=/home/foo/', '/baz/bar.txt'),
|
array('/home/foo/bar.txt', '/var/www/=/files/,/home/foo/=/baz/', '/baz/bar.txt'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user