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

Commit

Permalink
Add support for non 443 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Witold Wasiczko committed Feb 24, 2015
1 parent 3f2dd66 commit e66c3d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Helper/ServerUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ protected function detectPort()
}

if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']) {
if ($this->isReversedProxy()) {
$this->setPort(443);
return;
}
$this->setPort($_SERVER['SERVER_PORT']);
return;
}
Expand All @@ -132,7 +136,7 @@ protected function detectScheme()
case (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)):
case (isset($_SERVER['HTTP_SCHEME']) && ($_SERVER['HTTP_SCHEME'] == 'https')):
case (443 === $this->getPort()):
case (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'):
case $this->isReversedProxy():
$scheme = 'https';
break;
default:
Expand All @@ -143,6 +147,11 @@ protected function detectScheme()
$this->setScheme($scheme);
}

protected function isReversedProxy()
{
return isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
}

/**
* Detect if a proxy is in use, and, if so, set the host based on it
*
Expand Down
1 change: 1 addition & 0 deletions test/Helper/ServerUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function testConstructorWithHostReversedProxyHttpsTrue()
{
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';
$_SERVER['SERVER_PORT'] = 80;

$url = new Helper\ServerUrl();
$this->assertEquals('https://example.com', $url->__invoke());
Expand Down

0 comments on commit e66c3d4

Please sign in to comment.