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

@rmasters

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

@rmasters 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
@weierophinney weierophinney closed this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3167'
Close #3167
Fixes #3161
ef156c1
@weierophinney

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

@rmasters

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

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3167'
Close #3167
Fixes #3161
26c4fcd
@ghost Unknown referenced this pull request from a commit
@weierophinney 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. @rmasters

    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.
View
11 library/Zend/View/Helper/ServerUrl.php
@@ -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;
}
View
9 tests/ZendTest/View/Helper/ServerUrlTest.php
@@ -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.