Feature #81628

Redirect Debugging

Added by Tizian Schmidlin about 2 years ago. Updated 5 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
Frontend
Start date:
2017-06-20
Due date:
% Done:

0%

PHP Version:
Tags:
Complexity:
Sprint Focus:
On Location Sprint

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.


Related issues

Related to TYPO3 Core - Epic #83652: EXT: Redirects module - Umbrella issue Accepted 2018-01-22
Related to TYPO3 Core - Task #86504: Redirects performed by sys_redirect records should send the uid of the record as response header Closed 2018-10-01

History

#1 Updated by Riccardo De Contardi over 1 year ago

  • Related to Epic #83652: EXT: Redirects module - Umbrella issue added

#2 Updated by Daniel Goerz 12 months ago

  • Related to Bug #86503: It is not possible to create a redirect for /index.php?id=123 added

#3 Updated by Daniel Goerz 12 months ago

  • Related to deleted (Bug #86503: It is not possible to create a redirect for /index.php?id=123)

#4 Updated by Daniel Goerz 12 months ago

  • Related to Task #86504: Redirects performed by sys_redirect records should send the uid of the record as response header added

#5 Updated by Susanne Moog 11 months ago

  • Sprint Focus set to On Location Sprint

#6 Updated by Benni Mack 11 months 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.

#7 Updated by Benni Mack 5 months ago

  • Target version changed from next-patchlevel to Candidate for patchlevel

Also available in: Atom PDF