From 9d7a97426d10d5a60ebaa22e6ac0d11edef96030 Mon Sep 17 00:00:00 2001 From: malc0mn Date: Wed, 11 Jul 2018 14:57:45 +0200 Subject: [PATCH 1/2] Add option to ignore SERVER_PORT getting added to url. --- lib/Raven/Client.php | 10 +++++++--- test/Raven/Tests/ClientTest.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Raven/Client.php b/lib/Raven/Client.php index 6d93ec3bd..7812dc178 100644 --- a/lib/Raven/Client.php +++ b/lib/Raven/Client.php @@ -91,6 +91,7 @@ class Raven_Client public $exclude; public $excluded_exceptions; public $http_proxy; + public $ignore_server_port; protected $send_callback; public $curl_method; public $curl_path; @@ -173,6 +174,7 @@ public function __construct($options_or_dsn = null, $options = array()) $this->excluded_exceptions = Raven_Util::get($options, 'excluded_exceptions', array()); $this->severity_map = null; $this->http_proxy = Raven_Util::get($options, 'http_proxy'); + $this->ignore_server_port = Raven_Util::get($options, 'ignore_server_port', false); $this->extra_data = Raven_Util::get($options, 'extra', array()); $this->send_callback = Raven_Util::get($options, 'send_callback', null); $this->curl_method = Raven_Util::get($options, 'curl_method', 'sync'); @@ -1311,9 +1313,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']; + if (!$this->ignore_server_port) { + $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' : ''; diff --git a/test/Raven/Tests/ClientTest.php b/test/Raven/Tests/ClientTest.php index c6cf634fb..460d985fb 100644 --- a/test/Raven/Tests/ClientTest.php +++ b/test/Raven/Tests/ClientTest.php @@ -1803,6 +1803,16 @@ public function currentUrlProvider() array(), 'http://example.com:81/', 'Port is not appended' + ), + array( + array( + 'REQUEST_URI' => '/', + 'HTTP_HOST' => 'example.com', + 'SERVER_PORT' => 81 + ), + array('ignore_server_port' => true), + 'http://example.com/', + 'Port is appended' ) ); } From a46b77e22db62d337f3323f0da05fdf0a2ef0b3b Mon Sep 17 00:00:00 2001 From: malc0mn Date: Mon, 16 Jul 2018 10:51:19 +0200 Subject: [PATCH 2/2] Updated docs to include ignore_server_port explanation. --- docs/config.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/config.rst b/docs/config.rst index f153398e3..17e7fdcd6 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -261,6 +261,17 @@ The following settings are available for the client: 'excluded_exceptions' => array('LogicException'), +.. describe:: ignore_server_port + + By default the server port will be added to the logged URL when it is a non + standard port (80, 443). + Setting this to ``true`` will ignore the server port altogether and will + result in the server port never getting appended to the logged URL. + + .. code-block:: php + + 'ignore_server_port' => true, + .. _sentry-php-request-context: Providing Request Context