Skip to content

Commit

Permalink
Fixed server HTTP_HOST port uri conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
bcremer authored and fabpot committed Jul 25, 2014
1 parent 4dbe0e1 commit f401ab9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -304,7 +304,11 @@ public function request($method, $uri, array $parameters = array(), array $files
$uri = $this->getAbsoluteUri($uri);

if (isset($server['HTTP_HOST'])) {
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
if ($port = parse_url($uri, PHP_URL_PORT)) {
$port = ':'.$port;
}

$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).$port.'}', '${1}'.$server['HTTP_HOST'], $uri);
}

if (isset($server['HTTPS'])) {
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -210,6 +210,24 @@ public function testRequestURIConversion()
$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.example.com:8000');
$parameters = array();
$files = array();

$client->request('GET', 'http://example.com', $parameters, $files, $server);
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');

$client->request('GET', 'http://example.com:8888', $parameters, $files, $server);
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');

$client->request('GET', 'http://example.com:8000', $parameters, $files, $server);
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
}

public function testRequestReferer()
{
$client = new TestClient();
Expand Down

0 comments on commit f401ab9

Please sign in to comment.