From 402199fa1124fb93969ee43f88bc7d8a36ba82b7 Mon Sep 17 00:00:00 2001 From: Thomas Rothe Date: Mon, 5 Mar 2018 08:59:12 +0100 Subject: [PATCH] Handle and add non default port to host (#558) --- lib/Raven/Client.php | 5 +++++ test/Raven/Tests/ClientTest.php | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index d547760f0..984cb851f 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -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']}"; } diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index 95e114f58..528eddabe 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -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' ) ); }