Skip to content

Commit

Permalink
Merge pull request #386 from rokclimb15/serverurl-helper-x-forwarded-…
Browse files Browse the repository at this point in the history
…proto

Support X-Forwarded-Proto header
  • Loading branch information
develart-projects authored Oct 26, 2023
2 parents 74ce53b + fa81714 commit e90fae7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/Zend/View/Helper/ServerUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function __construct()
case (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] === true)):
case (isset($_SERVER['HTTP_SCHEME']) && ($_SERVER['HTTP_SCHEME'] == 'https')):
case (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)):
case (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')):
$scheme = 'https';
break;
default:
Expand Down
10 changes: 10 additions & 0 deletions tests/Zend/View/Helper/ServerUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function set_up()
{
$this->_serverBackup = $_SERVER;
unset($_SERVER['HTTPS']);
unset($_SERVER['HTTP_X_FORWARDED_PROTO']);
}

/**
Expand Down Expand Up @@ -88,6 +89,15 @@ public function testConstructorWithHostAndHttpsOn()
$this->assertEquals('https://example.com', $url->serverUrl());
}

public function testConstructorWithHostAndXForwardedProtoHttps()
{
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['HTTP_X_FORWARDED_PROTO'] = 'https';

$url = new Zend_View_Helper_ServerUrl();
$this->assertEquals('https://example.com', $url->serverUrl());
}

public function testConstructorWithHostAndHttpsTrue()
{
$_SERVER['HTTP_HOST'] = 'example.com';
Expand Down

0 comments on commit e90fae7

Please sign in to comment.