Skip to content

Commit 1c4e2f3

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Routing] fix trailing slash redirection when using RedirectableUrlMatcher [PropertyAccessor] fix encoding of cache keys [WebProfiler] Detect empty file paths in file viewer fixed CS Changes for upcoming Travis' infra migration Doc fix: clarify isMethodCacheable() returns true only for GET & HEAD [DomCrawler] exclude fields inside "template" tags Use XLIFF source rather than resname when there's no target [DoctrineBridge] catch errors while converting to db values in data collector [DoctrineBridge] fix case sensitivity issue in RememberMe\DoctrineTokenProvider [EventDispatcher] Unwrap wrapped listeners internally Indentation error [HttpFoundation] Fix trailing space for mime-type with parameters [HttpFoundation] Fixed absolute Request URI with default port properly parse backslashes in unquoted env vars Use intersection type when referring to ParentNodeDefinitionInterface [BrowserKit] fixed BC Break for HTTP_HOST header; implemented same behaviour for HTTPS server parameter
2 parents f5edd8e + 49465af commit 1c4e2f3

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Client.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,17 @@ public function request(string $method, string $uri, array $parameters = array()
319319
++$this->redirectCount;
320320
}
321321

322+
$originalUri = $uri;
323+
322324
$uri = $this->getAbsoluteUri($uri);
323325

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

326-
if (isset($server['HTTPS'])) {
328+
if (!empty($server['HTTP_HOST']) && null === parse_url($originalUri, PHP_URL_HOST)) {
329+
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
330+
}
331+
332+
if (isset($server['HTTPS']) && null === parse_url($originalUri, PHP_URL_SCHEME)) {
327333
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
328334
}
329335

Tests/ClientTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ public function testSetServerParameterInRequest()
741741
$this->assertEquals('', $client->getServerParameter('HTTP_HOST'));
742742
$this->assertEquals('Symfony BrowserKit', $client->getServerParameter('HTTP_USER_AGENT'));
743743

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

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

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

757757
$this->assertArrayHasKey('HTTPS', $server);
758-
$this->assertFalse($server['HTTPS']);
758+
$this->assertTrue($server['HTTPS']);
759+
}
760+
761+
public function testRequestWithRelativeUri()
762+
{
763+
$client = new TestClient();
764+
765+
$client->request('GET', '/', array(), array(), array(
766+
'HTTP_HOST' => 'testhost',
767+
'HTTPS' => true,
768+
));
769+
$this->assertEquals('https://testhost/', $client->getRequest()->getUri());
770+
771+
$client->request('GET', 'https://www.example.com/', array(), array(), array(
772+
'HTTP_HOST' => 'testhost',
773+
'HTTPS' => false,
774+
));
775+
$this->assertEquals('https://www.example.com/', $client->getRequest()->getUri());
759776
}
760777

761778
public function testInternalRequest()

0 commit comments

Comments
 (0)