diff --git a/library/Zend/Http/PhpEnvironment/Request.php b/library/Zend/Http/PhpEnvironment/Request.php index a680e340765..aa9d56a5371 100755 --- a/library/Zend/Http/PhpEnvironment/Request.php +++ b/library/Zend/Http/PhpEnvironment/Request.php @@ -163,9 +163,6 @@ public function setServer(ParametersDescription $server) $uri->setQuery($this->serverParams['QUERY_STRING']); } - $requestUri = $this->getRequestUri(); - $uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri))); - if ($this->headers()->get('host')) { //TODO handle IPv6 with port if (preg_match('|^([^:]+):([^:]+)$|', $this->headers()->get('host')->getFieldValue(), $match)) { @@ -182,6 +179,9 @@ public function setServer(ParametersDescription $server) } } + $requestUri = $this->getRequestUri(); + $uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri))); + return $this; } diff --git a/tests/Zend/Http/PhpEnvironment/RequestTest.php b/tests/Zend/Http/PhpEnvironment/RequestTest.php index 69471c52c91..1192e1949bc 100644 --- a/tests/Zend/Http/PhpEnvironment/RequestTest.php +++ b/tests/Zend/Http/PhpEnvironment/RequestTest.php @@ -235,4 +235,38 @@ public function testHeadersWithMinus(array $server, $name, $value) $this->assertEquals($value, $header->getFieldValue($value)); } + /** + * Data provider for testing server hostname. + */ + public static function serverHostnameProvider() + { + return array( + array( + array( + 'SERVER_NAME' => 'test.example.com', + 'REQUEST_URI' => 'http://test.example.com/news', + ), + 'test.example.com', + '/news', + ), + ); + } + + /** + * @dataProvider serverHostnameProvider + * @param array $server + * @param string $name + * @param string $value + */ + public function testServerHostnameProvider(array $server, $expectedHost, $expectedRequestUri) + { + $_SERVER = $server; + $request = new Request(); + + $host = $request->uri()->getHost(); + $this->assertEquals($expectedHost, $host); + + $requestUri = $request->getRequestUri(); + $this->assertEquals($expectedRequestUri, $requestUri); + } }