merged branch bendavies/iis-rewrite-subrequests (PR #7606)
This PR was merged into the 2.1 branch.
Discussion
----------
[HttpFoundation] fixes creation of sub requests under IIS & Rewite Module
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #6936, #6923
| License | MIT
| Doc PR | N/A
There are a few bugs to address.
1. `HTTP_X_ORIGINAL_URL` wasn't removed from the server parameters, so is picked back up [here](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/ServerBag.php#L33) upon recreation of a sub request.
2. When `X_ORIGINAL_URL` is passed in the headers by IIS, `IIS_WasUrlRewritten` and `UNENCODED_URL` can also be passed as server vars, so they must also be removed for sub request URI's to be resolved correctly.
Additionally, I have removed the OS check for windows, because it was only done for 2 out of 4 of the IIS specific checks, and it made the code untestable.
Also added tests for all scenarios as there were none.
Commits
-------
9fcd2f6
[HttpFoundation] fixed the creation of sub-requests under some circumstances for IIS
This commit is contained in:
commit
1454af7235
@ -1436,11 +1436,14 @@ class Request
|
|||||||
{
|
{
|
||||||
$requestUri = '';
|
$requestUri = '';
|
||||||
|
|
||||||
if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
if ($this->headers->has('X_ORIGINAL_URL')) {
|
||||||
// IIS with Microsoft Rewrite Module
|
// IIS with Microsoft Rewrite Module
|
||||||
$requestUri = $this->headers->get('X_ORIGINAL_URL');
|
$requestUri = $this->headers->get('X_ORIGINAL_URL');
|
||||||
$this->headers->remove('X_ORIGINAL_URL');
|
$this->headers->remove('X_ORIGINAL_URL');
|
||||||
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
|
$this->server->remove('HTTP_X_ORIGINAL_URL');
|
||||||
|
$this->server->remove('UNENCODED_URL');
|
||||||
|
$this->server->remove('IIS_WasUrlRewritten');
|
||||||
|
} elseif ($this->headers->has('X_REWRITE_URL')) {
|
||||||
// IIS with ISAPI_Rewrite
|
// IIS with ISAPI_Rewrite
|
||||||
$requestUri = $this->headers->get('X_REWRITE_URL');
|
$requestUri = $this->headers->get('X_REWRITE_URL');
|
||||||
$this->headers->remove('X_REWRITE_URL');
|
$this->headers->remove('X_REWRITE_URL');
|
||||||
|
@ -1234,6 +1234,95 @@ class RequestTest extends \PHPUnit_Framework_TestCase
|
|||||||
// reset
|
// reset
|
||||||
Request::setTrustedProxies(array());
|
Request::setTrustedProxies(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider iisRequestUriProvider
|
||||||
|
*/
|
||||||
|
public function testIISRequestUri($headers, $server, $expectedRequestUri)
|
||||||
|
{
|
||||||
|
$request = new Request();
|
||||||
|
$request->headers->replace($headers);
|
||||||
|
$request->server->replace($server);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');
|
||||||
|
|
||||||
|
$subRequestUri = '/bar/foo';
|
||||||
|
$subRequest = $request::create($subRequestUri, 'get', array(), array(), array(), $request->server->all());
|
||||||
|
$this->assertEquals($subRequestUri, $subRequest->getRequestUri(), '->getRequestUri() is correct in sub request');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function iisRequestUriProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'X_ORIGINAL_URL' => '/foo/bar',
|
||||||
|
),
|
||||||
|
array(),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'X_REWRITE_URL' => '/foo/bar',
|
||||||
|
),
|
||||||
|
array(),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'IIS_WasUrlRewritten' => '1',
|
||||||
|
'UNENCODED_URL' => '/foo/bar'
|
||||||
|
),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'X_ORIGINAL_URL' => '/foo/bar',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'HTTP_X_ORIGINAL_URL' => '/foo/bar'
|
||||||
|
),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'X_ORIGINAL_URL' => '/foo/bar',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'IIS_WasUrlRewritten' => '1',
|
||||||
|
'UNENCODED_URL' => '/foo/bar'
|
||||||
|
),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'X_ORIGINAL_URL' => '/foo/bar',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
|
||||||
|
'IIS_WasUrlRewritten' => '1',
|
||||||
|
'UNENCODED_URL' => '/foo/bar'
|
||||||
|
),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'ORIG_PATH_INFO' => '/foo/bar',
|
||||||
|
),
|
||||||
|
'/foo/bar'
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array(),
|
||||||
|
array(
|
||||||
|
'ORIG_PATH_INFO' => '/foo/bar',
|
||||||
|
'QUERY_STRING' => 'foo=bar',
|
||||||
|
),
|
||||||
|
'/foo/bar?foo=bar'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RequestContentProxy extends Request
|
class RequestContentProxy extends Request
|
||||||
|
Reference in New Issue
Block a user