Skip to content

Commit 3ce5ac0

Browse files
committed
bug symfony#10078 [BrowserKit] add non-standard port to HTTP_HOST server param (kbond)
This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes symfony#10078). Discussion ---------- [BrowserKit] add non-standard port to HTTP_HOST server param | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | https://github.com/Behat/MinkGoutteDriver/issues/25 | License | MIT | Doc PR | n/a This fix will allow using BrowserKit with php's webserver. Commits ------- 5f25639 [BrowserKit] add non-standard port to HTTP_HOST
2 parents d99507b + 247604c commit 3ce5ac0

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
@@ -302,12 +302,18 @@ public function request($method, $uri, array $parameters = array(), array $files
302302
}
303303

304304
$uri = $this->getAbsoluteUri($uri);
305-
306305
$server = array_merge($this->server, $server);
306+
307307
if (!$this->history->isEmpty()) {
308308
$server['HTTP_REFERER'] = $this->history->current()->getUri();
309309
}
310+
310311
$server['HTTP_HOST'] = parse_url($uri, PHP_URL_HOST);
312+
313+
if ($port = parse_url($uri, PHP_URL_PORT)) {
314+
$server['HTTP_HOST'] .= ':'.$port;
315+
}
316+
311317
$server['HTTPS'] = 'https' == parse_url($uri, PHP_URL_SCHEME);
312318

313319
$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()
@@ -448,6 +453,24 @@ public function testFollowRedirectWithHeaders()
448453
$this->assertEquals($headers, $client->getRequest()->getServer());
449454
}
450455

456+
public function testFollowRedirectWithPort()
457+
{
458+
$headers = array(
459+
'HTTP_HOST' => 'www.example.com:8080',
460+
'HTTP_USER_AGENT' => 'Symfony2 BrowserKit',
461+
'HTTPS' => false
462+
);
463+
464+
$client = new TestClient();
465+
$client->followRedirects(false);
466+
$client->setNextResponse(new Response('', 302, array(
467+
'Location' => 'http://www.example.com:8080/redirected',
468+
)));
469+
$client->request('GET', 'http://www.example.com:8080/');
470+
471+
$this->assertEquals($headers, $client->getRequest()->getServer());
472+
}
473+
451474
public function testBack()
452475
{
453476
$client = new TestClient();

0 commit comments

Comments
 (0)