[HttpFoundation] fixed the creation of sub-requests under some circumstances for IIS

This commit is contained in:
Ben Davies 2013-04-08 17:34:47 +01:00
parent 12b7073607
commit 9fcd2f6005
2 changed files with 94 additions and 2 deletions

View File

@ -1435,11 +1435,14 @@ class Request
{
$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
$requestUri = $this->headers->get('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
$requestUri = $this->headers->get('X_REWRITE_URL');
$this->headers->remove('X_REWRITE_URL');

View File

@ -1231,6 +1231,95 @@ class RequestTest extends \PHPUnit_Framework_TestCase
// reset
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