Project

General

Profile

Actions

Feature #81628

closed

Redirect Debugging

Added by Tizian Schmidlin almost 7 years ago. Updated about 4 years ago.

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

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

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 2 (0 open2 closed)

Related to TYPO3 Core - Epic #83652: EXT: Redirects module - Umbrella issueClosed2018-01-22

Actions
Related to TYPO3 Core - Task #86504: Redirects performed by sys_redirect records should send the uid of the record as response headerClosedDaniel Goerz2018-10-01

Actions
Actions

Also available in: Atom PDF