Skip to content

Commit 680e73c

Browse files
Merge branch '4.1'
* 4.1: (23 commits) [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 [MonologBridge] Return empty list for unknonwn requests [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 [Routing] fix trailing slash redirection when using RedirectableUrlMatcher Removed the return type phpdoc fix authorization checker variable name [Routing] Remove duplicate schemes and methods for invokable controllers Indentation error [HttpFoundation] Fix trailing space for mime-type with parameters [HttpFoundation] Fixed absolute Request URI with default port [Bridge/PhpUnit] fix the fix ...
2 parents 5bb3199 + 1c4e2f3 commit 680e73c

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
@@ -367,11 +367,17 @@ public function request(string $method, string $uri, array $parameters = array()
367367
++$this->redirectCount;
368368
}
369369

370+
$originalUri = $uri;
371+
370372
$uri = $this->getAbsoluteUri($uri);
371373

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

374-
if (isset($server['HTTPS'])) {
376+
if (!empty($server['HTTP_HOST']) && null === parse_url($originalUri, PHP_URL_HOST)) {
377+
$uri = preg_replace('{^(https?\://)'.preg_quote($this->extractHost($uri)).'}', '${1}'.$server['HTTP_HOST'], $uri);
378+
}
379+
380+
if (isset($server['HTTPS']) && null === parse_url($originalUri, PHP_URL_SCHEME)) {
375381
$uri = preg_replace('{^'.parse_url($uri, PHP_URL_SCHEME).'}', $server['HTTPS'] ? 'https' : 'http', $uri);
376382
}
377383

Tests/ClientTest.php

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

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

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

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

854854
$this->assertArrayHasKey('HTTPS', $server);
855-
$this->assertFalse($server['HTTPS']);
855+
$this->assertTrue($server['HTTPS']);
856+
}
857+
858+
public function testRequestWithRelativeUri()
859+
{
860+
$client = new TestClient();
861+
862+
$client->request('GET', '/', array(), array(), array(
863+
'HTTP_HOST' => 'testhost',
864+
'HTTPS' => true,
865+
));
866+
$this->assertEquals('https://testhost/', $client->getRequest()->getUri());
867+
868+
$client->request('GET', 'https://www.example.com/', array(), array(), array(
869+
'HTTP_HOST' => 'testhost',
870+
'HTTPS' => false,
871+
));
872+
$this->assertEquals('https://www.example.com/', $client->getRequest()->getUri());
856873
}
857874

858875
public function testInternalRequest()

0 commit comments

Comments
 (0)