MDL-69779 core: Improved the X-Redirect-By header when debugging is on

This commit is contained in:
Brendan Heywood 2020-09-24 16:30:39 +10:00
parent 46f977a8bf
commit 16c209cbc0
2 changed files with 11 additions and 2 deletions

View file

@ -52,6 +52,7 @@ information provided here is intended especially for developers.
renamed to `is_listed()` and `get_not_listed()` respectively. renamed to `is_listed()` and `get_not_listed()` respectively.
* Method `mustache_helper_collection::strip_blacklisted_helpers()` has been deprecated and renamed to * Method `mustache_helper_collection::strip_blacklisted_helpers()` has been deprecated and renamed to
`strip_disallowed_helpers()`. `strip_disallowed_helpers()`.
* Function redirect() now emits a line of backtrace into the X-Redirect-By header when debugging is one
=== 3.9 === === 3.9 ===
* Following function has been deprecated, please use \core\task\manager::run_from_cli(). * Following function has been deprecated, please use \core\task\manager::run_from_cli().

View file

@ -2954,9 +2954,17 @@ function redirect($url, $message='', $delay=null, $messagetype = \core\output\no
\core\session\manager::write_close(); \core\session\manager::write_close();
if ($delay == 0 && !$debugdisableredirect && !headers_sent()) { if ($delay == 0 && !$debugdisableredirect && !headers_sent()) {
// This helps when debugging redirect issues like loops and it is not clear // This helps when debugging redirect issues like loops and it is not clear
// which layer in the stack sent the redirect header. // which layer in the stack sent the redirect header. If debugging is on
@header('X-Redirect-By: Moodle'); // then the file and line is also shown.
$redirectby = 'Moodle';
if (debugging('', DEBUG_DEVELOPER)) {
$origin = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0];
$redirectby .= ' /' . str_replace($CFG->dirroot . '/', '', $origin['file']) . ':' . $origin['line'];
}
@header("X-Redirect-By: $redirectby");
// 302 might not work for POST requests, 303 is ignored by obsolete clients. // 302 might not work for POST requests, 303 is ignored by obsolete clients.
@header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other');
@header('Location: '.$url); @header('Location: '.$url);