Browse Source

Merge branch 'highstrike-referer-error-log' into master.

Add referer URL into logs if the referrer is defined.

Refs #8089
Mark Story 10 years ago
parent
commit
cffbda24e4
2 changed files with 14 additions and 5 deletions
  1. 9 4
      src/Error/BaseErrorHandler.php
  2. 5 1
      tests/TestCase/Error/ErrorHandlerTest.php

+ 9 - 4
src/Error/BaseErrorHandler.php

@@ -292,12 +292,17 @@ abstract class BaseErrorHandler
                 $message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
             }
         }
-        if ((PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg')) {
-            $request = Router::getRequest();
-            if ($request) {
-                $message .= "\nRequest URL: " . $request->here();
+
+        $request = Router::getRequest();
+        if ($request) {
+            $message .= "\nRequest URL: " . $request->here();
+
+            $referer = $request->env('HTTP_REFERER');
+            if ($referer) {
+                $message .= "\nReferer URL: " . $referer;
             }
         }
+
         if (!empty($config['trace'])) {
             $message .= "\nStack Trace:\n" . $exception->getTraceAsString() . "\n\n";
         }

+ 5 - 1
tests/TestCase/Error/ErrorHandlerTest.php

@@ -86,6 +86,8 @@ class ErrorHandlerTest extends TestCase
 
         $request = new Request();
         $request->base = '';
+        $request->env('HTTP_REFERER', '/referer');
+
         Router::setRequestInfo($request);
         Configure::write('debug', true);
 
@@ -304,7 +306,9 @@ class ErrorHandlerTest extends TestCase
                     '[Cake\Routing\Exception\MissingControllerException] ' .
                     'Controller class Derp could not be found.'
                 ),
-                $this->stringContains('Exception Attributes:')
+                $this->stringContains('Exception Attributes:'),
+                $this->stringContains('Request URL:'),
+                $this->stringContains('Referer URL:')
             ));
 
         $this->_logger->expects($this->at(1))