Skip to content

Commit 5f25639

Browse files
committed
[BrowserKit] add non-standard port to HTTP_HOST
1 parent 4ad343b commit 5f25639

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,18 @@ public function request($method, $uri, array $parameters = array(), array $files
295295
}
296296

297297
$uri = $this->getAbsoluteUri($uri);
298-
299298
$server = array_merge($this->server, $server);
299+
300300
if (!$this->history->isEmpty()) {
301301
$server['HTTP_REFERER'] = $this->history->current()->getUri();
302302
}
303+
303304
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
305+
306+
if ($port = parse_url($uri, PHP_URL_PORT)) {
307+
$server['HTTP_HOST'] .= ':'.$port;
308+
}
309+
304310
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
305311

306312
$this->internalRequest = new Request($uri, $method, $parameters, $files, $this->cookieJar->allValues($uri), $server, $content);

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public function testRequestHttpHeaders()
160160
$client->request('GET', 'https://www.example.com');
161161
$headers = $client->getRequest()->getServer();
162162
$this->assertTrue($headers['HTTPS'], '->request() sets the HTTPS header');
163+
164+
$client = new TestClient();
165+
$client->request('GET', 'http://www.example.com:8080');
166+
$headers = $client->getRequest()->getServer();
167+
$this->assertEquals('www.example.com:8080', $headers['HTTP_HOST'], '->request() sets the HTTP_HOST header with port');
163168
}
164169

165170
public function testRequestURIConversion()
@@ -416,6 +421,24 @@ public function testFollowRedirectWithHeaders()
416421
$this->assertEquals($headers, $client->getRequest()->getServer());
417422
}
418423

424+
public function testFollowRedirectWithPort()
425+
{
426+
$headers = array(
427+
'HTTP_HOST' => 'www.example.com:8080',
428+
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
429+
'HTTPS' => false
430+
);
431+
432+
$client = new TestClient();
433+
$client->followRedirects(false);
434+
$client->setNextResponse(new Response('', 302, array(
435+
'Location' => 'http://www.example.com:8080/redirected',
436+
)));
437+
$client->request('GET', 'http://www.example.com:8080/');
438+
439+
$this->assertEquals($headers, $client->getRequest()->getServer());
440+
}
441+
419442
public function testBack()
420443
{
421444
$client = new TestClient();

0 commit comments

Comments
 (0)