Skip to content

Commit

Permalink
Merge pull request #572 from getsentry/fix-pr-558
Browse files Browse the repository at this point in the history
Handle and add non default port to host (#558)
  • Loading branch information
stayallive authored Mar 20, 2018
2 parents 047f0d3 + 402199f commit f3aa013
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,11 @@ protected function get_current_url()
: (!empty($_SERVER['LOCAL_ADDR']) ? $_SERVER['LOCAL_ADDR']
: (!empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '')));

$hasNonDefaultPort = !empty($_SERVER['SERVER_PORT']) && !in_array((int)$_SERVER['SERVER_PORT'], array(80, 443));
if ($hasNonDefaultPort && !preg_match('#:[0-9]*$#', $host)) {
$host .= ':' . $_SERVER['SERVER_PORT'];
}

$httpS = $this->isHttps() ? 's' : '';
return "http{$httpS}://{$host}{$_SERVER['REQUEST_URI']}";
}
Expand Down
10 changes: 10 additions & 0 deletions test/Raven/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,16 @@ public function currentUrlProvider()
array('trust_x_forwarded_proto' => true),
'https://example.com/',
'The url is expected to be https because the X-Forwarded header is trusted'
),
array(
array(
'REQUEST_URI' => '/',
'HTTP_HOST' => 'example.com',
'SERVER_PORT' => 81
),
array(),
'http://example.com:81/',
'Port is not appended'
)
);
}
Expand Down

0 comments on commit f3aa013

Please # to comment.