Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BrowserKit] fixed BC Break for HTTP_HOST header #26244

Merged
merged 1 commit into from Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Expand Up @@ -259,11 +259,17 @@ public function request($method, $uri, array $parameters = array(), array $files
++$this->redirectCount;
}

$originalUri = $uri;

$uri = $this->getAbsoluteUri($uri);

$server = array_merge($this->server, $server);

if (isset($server['HTTPS'])) {
if (!empty($server['HTTP_HOST']) && null === parse_url($originalUri, PHP_URL_HOST)) {
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
}

if (isset($server['HTTPS']) && null === parse_url($originalUri, PHP_URL_SCHEME)) {
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
}

Expand Down
21 changes: 19 additions & 2 deletions src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Expand Up @@ -622,7 +622,7 @@ public function testSetServerParameterInRequest()
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));

$this->assertEquals('http://www.example.com/https/www.example.com', $client->getRequest()->getUri());
$this->assertEquals('https://www.example.com/https/www.example.com', $client->getRequest()->getUri());

$server = $client->getRequest()->getServer();

Expand All @@ -636,7 +636,24 @@ public function testSetServerParameterInRequest()
$this->assertEquals('new-server-key-value', $server['NEW_SERVER_KEY']);

$this->assertArrayHasKey('HTTPS', $server);
$this->assertFalse($server['HTTPS']);
$this->assertTrue($server['HTTPS']);
}

public function testRequestWithRelativeUri()
{
$client = new TestClient();

$client->request('GET', '/', array(), array(), array(
'HTTP_HOST' => 'testhost',
'HTTPS' => true,
));
$this->assertEquals('https://testhost/', $client->getRequest()->getUri());

$client->request('GET', 'https://www.example.com/', array(), array(), array(
'HTTP_HOST' => 'testhost',
'HTTPS' => false,
));
$this->assertEquals('https://www.example.com/', $client->getRequest()->getUri());
}

public function testInternalRequest()
Expand Down