Skip to content

Commit

Permalink
Merge branch 'MDL-69779-better-x-redirect-by' of https://github.com/b…
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed Oct 13, 2020
2 parents 01fe171 + 16c209c commit df61149
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ information provided here is intended especially for developers.
* A new admin externalpage type `\core_admin\local\externalpage\accesscallback` for use in plugin settings is available that allows
a callback to be provided to determine whether page can be accessed.
* New setting $CFG->localtempdir overrides which defaults to sys_get_temp_dir()
* Function redirect() now emits a line of backtrace into the X-Redirect-By header when debugging is on

=== 3.9 ===
* Following function has been deprecated, please use \core\task\manager::run_from_cli().
Expand Down
12 changes: 10 additions & 2 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2954,9 +2954,17 @@ function redirect($url, $message='', $delay=null, $messagetype = \core\output\no
\core\session\manager::write_close();

if ($delay == 0 && !$debugdisableredirect && !headers_sent()) {

// This helps when debugging redirect issues like loops and it is not clear
// which layer in the stack sent the redirect header.
@header('X-Redirect-By: Moodle');
// which layer in the stack sent the redirect header. If debugging is on
// 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.
@header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other');
@header('Location: '.$url);
Expand Down

0 comments on commit df61149

Please sign in to comment.