[BrowserKit] fixed BC Break for HTTP_HOST header; implemented same behaviour for HTTPS server parameter

This commit is contained in:
Alexander Pasichnick 2018-02-20 19:48:33 +03:00
parent cb53f4ccd5
commit 8c4a59467f
2 changed files with 26 additions and 3 deletions

View File

@ -259,11 +259,17 @@ abstract class Client
++$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);
}

View File

@ -622,7 +622,7 @@ class ClientTest extends TestCase
$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();
@ -636,7 +636,24 @@ class ClientTest extends TestCase
$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()