Skip to content

Commit

Permalink
Ensure that we determine the requestUri after we have determined the …
Browse files Browse the repository at this point in the history
…hostname and port
  • Loading branch information
akrabat committed Mar 20, 2012
1 parent c1d855e commit 89635e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Http/PhpEnvironment/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -182,6 +179,9 @@ public function setServer(ParametersDescription $server)
}
}

$requestUri = $this->getRequestUri();
$uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri)));

return $this;
}

Expand Down
34 changes: 34 additions & 0 deletions tests/Zend/Http/PhpEnvironment/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 89635e9

Please sign in to comment.