Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit acb7db5

Browse filesBrowse files
committed
[BrowserKit] fixed BC Break for HTTP_HOST header; implemented same behaviour for HTTPS server parameter
1 parent cb53f4c commit acb7db5
Copy full SHA for acb7db5

File tree

Expand file treeCollapse file tree

2 files changed

+26
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-3
lines changed

‎src/Symfony/Component/BrowserKit/Client.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Client.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,17 @@ public function request($method, $uri, array $parameters = array(), array $files
259259
++$this->redirectCount;
260260
}
261261

262+
$originalUri = $uri;
263+
262264
$uri = $this->getAbsoluteUri($uri);
263265

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

266-
if (isset($server['HTTPS'])) {
268+
if (!empty($server['HTTP_HOST']) && parse_url($originalUri, PHP_URL_HOST) === null) {
269+
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
270+
}
271+
272+
if (isset($server['HTTPS']) && parse_url($originalUri, PHP_URL_SCHEME) === null) {
267273
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
268274
}
269275

‎src/Symfony/Component/BrowserKit/Tests/ClientTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/Tests/ClientTest.php
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ public function testSetServerParameterInRequest()
622622
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
623623
$this->assertEquals('Symfony2 BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
624624

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

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

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

638638
$this->assertArrayHasKey('HTTPS', $server);
639-
$this->assertFalse($server['HTTPS']);
639+
$this->assertTrue($server['HTTPS']);
640+
}
641+
642+
public function testRequestWithRelativeUri()
643+
{
644+
$client = new TestClient();
645+
646+
$client->request('GET', '/', array(), array(), array(
647+
'HTTP_HOST' => 'testhost',
648+
'HTTPS' => true
649+
));
650+
$this->assertEquals('https://testhost/', $client->getRequest()->getUri());
651+
652+
$client->request('GET', 'https://www.example.com/', array(), array(), array(
653+
'HTTP_HOST' => 'testhost',
654+
'HTTPS' => false
655+
));
656+
$this->assertEquals('https://www.example.com/', $client->getRequest()->getUri());
640657
}
641658

642659
public function testInternalRequest()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.