Skip to content

Commit

Permalink
Merge pull request zendframework#5846
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Feb 22, 2014
2 parents 452ca1a + ef7cc33 commit 1cbb52e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions library/Zend/Http/PhpEnvironment/Request.php
Expand Up @@ -251,8 +251,13 @@ public function setServer(ParametersInterface $server)
$uri = new HttpUri();

// URI scheme
$scheme = (!empty($this->serverParams['HTTPS'])
&& $this->serverParams['HTTPS'] !== 'off') ? 'https' : 'http';
if ((!empty($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] !== 'off')
|| (!empty($this->serverParams['HTTP_X_FORWARDED_PROTO']) && $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https')
) {
$scheme = 'https';
} else {
$scheme = 'http';
}
$uri->setScheme($scheme);

// URI host & port
Expand Down
18 changes: 18 additions & 0 deletions tests/ZendTest/Http/PhpEnvironment/RequestTest.php
Expand Up @@ -387,6 +387,18 @@ public static function serverHostnameProvider()
'443',
'/news',
),
// Test for HTTPS requests which are forwarded over a reverse proxy/load balancer
array(
array(
'SERVER_NAME' => 'test.example.com',
'SERVER_PORT' => '443',
'HTTP_X_FORWARDED_PROTO' => 'https',
'REQUEST_URI' => 'https://test.example.com/news',
),
'test.example.com',
'443',
'/news',
),

//Test when url quert contains a full http url
array(
Expand Down Expand Up @@ -416,6 +428,12 @@ public function testServerHostnameProvider(array $server, $expectedHost, $expect
$host = $request->getUri()->getHost();
$this->assertEquals($expectedHost, $host);

$uriParts = parse_url($_SERVER['REQUEST_URI']);
if (isset($uriParts['scheme'])) {
$scheme = $request->getUri()->getScheme();
$this->assertEquals($uriParts['scheme'], $scheme);
}

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

Expand Down

0 comments on commit 1cbb52e

Please sign in to comment.