bug #11469 [BrowserKit] Fixed server HTTP_HOST port uri conversion (bcremer, fabpot)
This PR was merged into the 2.3 branch. Discussion ---------- [BrowserKit] Fixed server HTTP_HOST port uri conversion | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11356 | License | MIT | Doc PR | n/a See #11356 Commits -------103fd88
[BrowserKit] refactor code and fix unquoted regexf401ab9
Fixed server HTTP_HOST port uri conversion
This commit is contained in:
commit
94ffc4fab2
@ -304,7 +304,7 @@ abstract class Client
|
|||||||
$uri = $this->getAbsoluteUri($uri);
|
$uri = $this->getAbsoluteUri($uri);
|
||||||
|
|
||||||
if (isset($server['HTTP_HOST'])) {
|
if (isset($server['HTTP_HOST'])) {
|
||||||
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
|
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($server['HTTPS'])) {
|
if (isset($server['HTTPS'])) {
|
||||||
@ -317,12 +317,7 @@ abstract class Client
|
|||||||
$server['HTTP_REFERER'] = $this->history->current()->getUri();
|
$server['HTTP_REFERER'] = $this->history->current()->getUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
|
$server['HTTP_HOST'] = $this->extractHost($uri);
|
||||||
|
|
||||||
if ($port = parse_url($uri, PHP_URL_PORT)) {
|
|
||||||
$server['HTTP_HOST'] .= ':'.$port;
|
|
||||||
}
|
|
||||||
|
|
||||||
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
|
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
|
||||||
|
|
||||||
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
|
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);
|
||||||
@ -619,4 +614,15 @@ abstract class Client
|
|||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function extractHost($uri)
|
||||||
|
{
|
||||||
|
$host = parse_url($uri, PHP_URL_HOST);
|
||||||
|
|
||||||
|
if ($port = parse_url($uri, PHP_URL_PORT)) {
|
||||||
|
return $host.':'.$port;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $host;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,24 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
|
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRequestURIConversionByServerHost()
|
||||||
|
{
|
||||||
|
$client = new TestClient();
|
||||||
|
|
||||||
|
$server = array('HTTP_HOST' => 'www.exampl+e.com:8000');
|
||||||
|
$parameters = array();
|
||||||
|
$files = array();
|
||||||
|
|
||||||
|
$client->request('GET', 'http://exampl+e.com', $parameters, $files, $server);
|
||||||
|
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');
|
||||||
|
|
||||||
|
$client->request('GET', 'http://exampl+e.com:8888', $parameters, $files, $server);
|
||||||
|
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');
|
||||||
|
|
||||||
|
$client->request('GET', 'http://exampl+e.com:8000', $parameters, $files, $server);
|
||||||
|
$this->assertEquals('http://www.exampl+e.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
|
||||||
|
}
|
||||||
|
|
||||||
public function testRequestReferer()
|
public function testRequestReferer()
|
||||||
{
|
{
|
||||||
$client = new TestClient();
|
$client = new TestClient();
|
||||||
|
Reference in New Issue
Block a user