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 #1

Updated by Riccardo De Contardi about 6 years ago

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

Updated by Daniel Goerz over 5 years ago

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

Updated by Daniel Goerz over 5 years ago

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

Updated by Daniel Goerz over 5 years ago

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

Updated by Susanne Moog over 5 years ago

  • Sprint Focus set to On Location Sprint
Actions #6

Updated by Benni Mack over 5 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.

Actions #7

Updated by Benni Mack about 5 years ago

  • Target version changed from next-patchlevel to Candidate for patchlevel
Actions #8

Updated by Susanne Moog over 4 years ago

  • Sprint Focus deleted (On Location Sprint)
Actions #9

Updated by Benni Mack about 4 years ago

  • Status changed from Needs Feedback to Closed

closed due to lack of feedback

Actions

Also available in: Atom PDF