Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix #3161 by checking if the server port already exists in the host #3167

Closed
wants to merge 1 commit into from

2 participants

Ross Masters Matthew Weier O'Phinney
Ross Masters

This occurs when running the PHP built-in webserver. HTTP_HOST is set
with the host passed to the script (which can include the port number).
SERVER_PORT is also set.

#3161

Ross Masters rmasters Fix #3161 by checking if the server port already exists in the host
This occurs when running the PHP built-in webserver. HTTP_HOST is set
with the host passed to the script (which can include the port number).
SERVER_PORT is also set.
50320b9
Matthew Weier O'Phinney weierophinney closed this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3167'
Close #3167
Fixes #3161
ef156c1
Matthew Weier O'Phinney

Had to cherry-pick, as this should apply against the master branch as well so that it can be in 2.0.6.

Ross Masters

Ah my bad, will know for next time. Cheers!

Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3167'
Close #3167
Fixes #3161
26c4fcd
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3167' into develop
Forward port #3167
6065eae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 4, 2012
  1. Ross Masters

    Fix #3161 by checking if the server port already exists in the host

    rmasters authored
    This occurs when running the PHP built-in webserver. HTTP_HOST is set
    with the host passed to the script (which can include the port number).
    SERVER_PORT is also set.
This page is out of date. Refresh to see the latest.
11 library/Zend/View/Helper/ServerUrl.php
View
@@ -98,7 +98,7 @@ public function setHost($host)
if (($scheme == 'http' && (null === $port || $port == 80))
|| ($scheme == 'https' && (null === $port || $port == 443))
) {
- $this->host = $host;;
+ $this->host = $host;
return $this;
}
@@ -180,6 +180,15 @@ protected function detectHost()
}
if (isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])) {
+ // Detect if the port is set in SERVER_PORT and included in HTTP_HOST
+ if (isset($_SERVER['SERVER_PORT'])) {
+ $portStr = ':' . $_SERVER['SERVER_PORT'];
+ if (substr($_SERVER['HTTP_HOST'], 0-strlen($portStr), strlen($portStr)) == $portStr) {
+ $this->setHost(substr($_SERVER['HTTP_HOST'], 0, 0-strlen($portStr)));
+ return;
+ }
+ }
+
$this->setHost($_SERVER['HTTP_HOST']);
return;
}
9 tests/ZendTest/View/Helper/ServerUrlTest.php
View
@@ -91,6 +91,15 @@ public function testConstructorWithHostIncludingPortAndHttpsTrue()
$this->assertEquals('https://example.com:8181', $url->__invoke());
}
+ public function testConstructorWithHttpHostIncludingPortAndPortSet()
+ {
+ $_SERVER['HTTP_HOST'] = 'example.com:8181';
+ $_SERVER['SERVER_PORT'] = 8181;
+
+ $url = new Helper\ServerUrl();
+ $this->assertEquals('http://example.com:8181', $url->__invoke());
+ }
+
public function testConstructorWithHttpHostAndServerNameAndPortSet()
{
$_SERVER['HTTP_HOST'] = 'example.com';
Something went wrong with that request. Please try again.