Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fcd2f6

Browse files
author
Ben Davies
committed
[HttpFoundation] fixed the creation of sub-requests under some circumstances for IIS
1 parent 12b7073 commit 9fcd2f6

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,14 @@ protected function prepareRequestUri()
14351435
{
14361436
$requestUri = '';
14371437

1438-
if ($this->headers->has('X_ORIGINAL_URL') && false !== stripos(PHP_OS, 'WIN')) {
1438+
if ($this->headers->has('X_ORIGINAL_URL')) {
14391439
// IIS with Microsoft Rewrite Module
14401440
$requestUri = $this->headers->get('X_ORIGINAL_URL');
14411441
$this->headers->remove('X_ORIGINAL_URL');
1442-
} elseif ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
1442+
$this->server->remove('HTTP_X_ORIGINAL_URL');
1443+
$this->server->remove('UNENCODED_URL');
1444+
$this->server->remove('IIS_WasUrlRewritten');
1445+
} elseif ($this->headers->has('X_REWRITE_URL')) {
14431446
// IIS with ISAPI_Rewrite
14441447
$requestUri = $this->headers->get('X_REWRITE_URL');
14451448
$this->headers->remove('X_REWRITE_URL');

src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,95 @@ public function testTrustedProxies()
12311231
// reset
12321232
Request::setTrustedProxies(array());
12331233
}
1234+
1235+
/**
1236+
* @dataProvider iisRequestUriProvider
1237+
*/
1238+
public function testIISRequestUri($headers, $server, $expectedRequestUri)
1239+
{
1240+
$request = new Request();
1241+
$request->headers->replace($headers);
1242+
$request->server->replace($server);
1243+
1244+
$this->assertEquals($expectedRequestUri, $request->getRequestUri(), '->getRequestUri() is correct');
1245+
1246+
$subRequestUri = '/bar/foo';
1247+
$subRequest = $request::create($subRequestUri, 'get', array(), array(), array(), $request->server->all());
1248+
$this->assertEquals($subRequestUri, $subRequest->getRequestUri(), '->getRequestUri() is correct in sub request');
1249+
}
1250+
1251+
public function iisRequestUriProvider()
1252+
{
1253+
return array(
1254+
array(
1255+
array(
1256+
'X_ORIGINAL_URL' => '/foo/bar',
1257+
),
1258+
array(),
1259+
'/foo/bar'
1260+
),
1261+
array(
1262+
array(
1263+
'X_REWRITE_URL' => '/foo/bar',
1264+
),
1265+
array(),
1266+
'/foo/bar'
1267+
),
1268+
array(
1269+
array(),
1270+
array(
1271+
'IIS_WasUrlRewritten' => '1',
1272+
'UNENCODED_URL' => '/foo/bar'
1273+
),
1274+
'/foo/bar'
1275+
),
1276+
array(
1277+
array(
1278+
'X_ORIGINAL_URL' => '/foo/bar',
1279+
),
1280+
array(
1281+
'HTTP_X_ORIGINAL_URL' => '/foo/bar'
1282+
),
1283+
'/foo/bar'
1284+
),
1285+
array(
1286+
array(
1287+
'X_ORIGINAL_URL' => '/foo/bar',
1288+
),
1289+
array(
1290+
'IIS_WasUrlRewritten' => '1',
1291+
'UNENCODED_URL' => '/foo/bar'
1292+
),
1293+
'/foo/bar'
1294+
),
1295+
array(
1296+
array(
1297+
'X_ORIGINAL_URL' => '/foo/bar',
1298+
),
1299+
array(
1300+
'HTTP_X_ORIGINAL_URL' => '/foo/bar',
1301+
'IIS_WasUrlRewritten' => '1',
1302+
'UNENCODED_URL' => '/foo/bar'
1303+
),
1304+
'/foo/bar'
1305+
),
1306+
array(
1307+
array(),
1308+
array(
1309+
'ORIG_PATH_INFO' => '/foo/bar',
1310+
),
1311+
'/foo/bar'
1312+
),
1313+
array(
1314+
array(),
1315+
array(
1316+
'ORIG_PATH_INFO' => '/foo/bar',
1317+
'QUERY_STRING' => 'foo=bar',
1318+
),
1319+
'/foo/bar?foo=bar'
1320+
)
1321+
);
1322+
}
12341323
}
12351324

12361325
class RequestContentProxy extends Request

0 commit comments

Comments
 (0)