Skip to content

Commit

Permalink
Merge pull request #629 from deltablue-cloud/master
Browse files Browse the repository at this point in the history
Add option to ignore SERVER_PORT getting added to url.
  • Loading branch information
stayallive authored Jul 17, 2018
2 parents ca117fd + a46b77e commit d574017
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions lib/Raven/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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' : '';
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 @@ -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'
)
);
}
Expand Down

0 comments on commit d574017

Please sign in to comment.