8000 Fixed server HTTP_HOST port uri conversion · symfony/symfony@f401ab9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f401ab9

Browse files
bcremerfabpot
authored andcommitted
Fixed server HTTP_HOST port uri conversion
1 parent 4dbe0e1 commit f401ab9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ public function request($method, $uri, array $parameters = array(), array $files
304304
$uri = $this->getAbsoluteUri($uri);
305305

306306
if (isset($server['HTTP_HOST'])) {
307-
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).'}', '${1}'.$server['HTTP_HOST'], $uri);
307+
if ($port = parse_url($uri, PHP_URL_PORT)) {
308+
$port = ':'.$port;
309+
}
310+
311+
$uri = preg_replace('{^(https?\://)'.parse_url($uri, PHP_URL_HOST).$port.'}', '${1}'.$server['HTTP_HOST'], $uri);
308312
}
309313

310314
if (isset($server['HTTPS'])) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ public function testRequestURIConversion()
210210
$this->assertEquals('http://www.example.com/foo/bar', $client->getRequest()->getUri(), '->request() uses the previous request for relative URLs');
211211
}
212212

213+
public function testRequestURIConversionByServerHost()
214+
{
215+
$client = new TestClient();
216+
217+
$server = array('HTTP_HOST' => 'www.example.com:8000');
218+
$parameters = array();
219+
$files = array();
220+
221+
$client->request('GET', 'http://example.com', $parameters, $files, $server);
222+
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to add port');
223+
224+
$client->request('GET', 'http://example.com:8888', $ 6D68 parameters, $files, $server);
225+
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST to modify existing port');
226+
227+
$client->request('GET', 'http://example.com:8000', $parameters, $files, $server);
228+
$this->assertEquals('http://www.example.com:8000', $client->getRequest()->getUri(), '->request() uses HTTP_HOST respects correct set port');
229+
}
230+
213231
public function testRequestReferer()
214232
{
215233
$client = new TestClient();

0 commit comments

Comments
 (0)
0