Feature #81628
closedRedirect Debugging
0%
Description
I've had several times the situation where I tried to figure out which part of TYPO3 redirected somewhere and therefore had to dig through lots of code just to figure out what part was messing with the redirects (for any reason: bad user input or bad coding is irrelevant in the end). Therefore I introduced a coding standard to my devs so that every redirect they program has to have a switchable header that tells us where the redirect happens. This happens by simply checking if the debug flag was set for frontend. This is a fairly easy approach but leads to a lot of spaghetti code, especially since everybody already uses HttpUtility::redirect.
Therefore my feature request:
- send an additional X-Redirect-By-Script header when debug mode is activated
This could be solved like this:
/**
* Sends a redirect header response and exits. Additionally the URL is
* checked and if needed corrected to match the format required for a
* Location redirect header. By default the HTTP status code sent is
* a 'HTTP/1.1 303 See Other'.
*
* @param string $url The target URL to redirect to
* @param string $httpStatus An optional HTTP status header. Default is 'HTTP/1.1 303 See Other'
*/
public static function redirect($url, $httpStatus = self::HTTP_STATUS_303)
{
self::setResponseCode($httpStatus);
if($GLOBALS['TYPO3_CONF_VARS']['FE']['debug']) {
// either work with debug_backtrace or get the trace from a new Exception
header('X-Redirect-By-Script: ' . $scriptName . ':'. $line);
}
header('Location: ' . GeneralUtility::locationHeaderUrl($url));
die;
}
I'm aware that everything that uses reflection to determine anything about itself or its origin is extremely expensive but that's far from any concern when debugging a nasty bug.
I'd like to have some feedback about the idea and would later on make a merge request for all 3 actively supported TYPO3 branches.
Thanks for your feedback.
Updated by Riccardo De Contardi almost 7 years ago
- Related to Epic #83652: EXT: Redirects module - Umbrella issue added
Updated by Daniel Goerz about 6 years ago
- Related to Bug #86503: It is not possible to create a redirect for /index.php?id=123 added
Updated by Daniel Goerz about 6 years ago
- Related to deleted (Bug #86503: It is not possible to create a redirect for /index.php?id=123)
Updated by Daniel Goerz about 6 years ago
- Related to Task #86504: Redirects performed by sys_redirect records should send the uid of the record as response header added
Updated by Susanne Moog about 6 years ago
- Sprint Focus set to On Location Sprint
Updated by Benni Mack about 6 years ago
- Status changed from New to Needs Feedback
we now built this in various other places with PSR-7 (RedirectResponse) where this could be built, and should be integrated. Feel free to add functionality like that directly, but I could imagine we add also a non-debug header (see EXT:redirects where we added that) to understand then where a redirect was added. Please target v9/master only.
Updated by Benni Mack over 5 years ago
- Target version changed from next-patchlevel to Candidate for patchlevel
Updated by Susanne Moog almost 5 years ago
- Sprint Focus deleted (
On Location Sprint)
Updated by Benni Mack over 4 years ago
- Status changed from Needs Feedback to Closed
closed due to lack of feedback