Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/zf2-499'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 28, 2012
6 parents 24efdcc + 219c9ad + 3025666 + e9fa593 + 2844dba + e5520e9 commit fec4cec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ public function setServer(ParametersInterface $server)
if (isset($this->serverParams['SERVER_PORT'])) {
$port = (int) $this->serverParams['SERVER_PORT'];
}
// Check for missinterpreted IPv6-Address
// Reported at least for Safari on Windows
if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
$host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
if ($port . ']' == substr($host, strrpos($host, ':')+1)) {
// The last digit of the IPv6-Address has been taken as port
// Unset the port so the default port can be used
$port = null;
}
}
} elseif ($this->getHeaders()->get('host')) {
$host = $this->getHeaders()->get('host')->getFieldValue();
// works for regname, IPv4 & IPv6
Expand Down
32 changes: 31 additions & 1 deletion test/PhpEnvironment/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public static function serverHostnameProvider()
'REQUEST_URI' => 'http://test.example.com/news',
),
'test.example.com',
'80',
'/news',
),
array(
Expand All @@ -309,6 +310,30 @@ public static function serverHostnameProvider()
'REQUEST_URI' => 'http://test.example.com/news',
),
'test.example.com',
'80',
'/news',
),
array(
array(
'SERVER_NAME' => '[1:2:3:4:5:6::6]',
'SERVER_ADDR' => '1:2:3:4:5:6::6',
'SERVER_PORT' => '80',
'REQUEST_URI' => 'http://[1:2:3:4:5:6::6]/news',
),
'[1:2:3:4:5:6::6]',
'80',
'/news',
),
// Test for broken $_SERVER implementation from Windows-Safari
array(
array(
'SERVER_NAME' => '[1:2:3:4:5:6:]',
'SERVER_ADDR' => '1:2:3:4:5:6::6',
'SERVER_PORT' => '6',
'REQUEST_URI' => 'http://[1:2:3:4:5:6::6]/news',
),
'[1:2:3:4:5:6::6]',
'80',
'/news',
),
array(
Expand All @@ -318,6 +343,7 @@ public static function serverHostnameProvider()
'REQUEST_URI' => 'http://test.example.com/news',
),
'test.example.com',
'8080',
'/news',
),
array(
Expand All @@ -328,6 +354,7 @@ public static function serverHostnameProvider()
'REQUEST_URI' => 'https://test.example.com/news',
),
'test.example.com',
'443',
'/news',
),
);
Expand All @@ -339,14 +366,17 @@ public static function serverHostnameProvider()
* @param string $name
* @param string $value
*/
public function testServerHostnameProvider(array $server, $expectedHost, $expectedRequestUri)
public function testServerHostnameProvider(array $server, $expectedHost, $expectedPort, $expectedRequestUri)
{
$_SERVER = $server;
$request = new Request();

$host = $request->getUri()->getHost();
$this->assertEquals($expectedHost, $host);

$port = $request->getUri()->getPort();
$this->assertEquals($expectedPort, $port);

$requestUri = $request->getRequestUri();
$this->assertEquals($expectedRequestUri, $requestUri);
}
Expand Down

0 comments on commit fec4cec

Please sign in to comment.