8000 [WebDebugToolbar] Redirection interception should only be triggered when request format is HTML · Issue #31168 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[WebDebugToolbar] Redirection interception should only be triggered when request format is HTML #31168
Closed
@bpolaszek

Description

@bpolaszek

Description
Currently, when setting intercept_redirects to true, the WDT will display a "Redirection intercepted!" page when it encounters a 201, 301, 302, 303, 307 or 308 along with a Location header.

The problem is that it doesn't filter the request format at this time, and as a consequence, WDT can even trigger an interception in an API context.

In a more concrete example, if you have the api-platform package installed and POST a new resource with Accept: application/json+ld, the application will return a 201 response with the freshly created resource Uri in the Location header.
But for the WebDebugToolbarListener, this is considered as a redirection and it should be intercepted.

Possible Solution
I suggest either adding 'html' === $request->getRequestFormat() as an additionnal condition for the interception to be triggered, or rely on $response->isRedirection() (>= 300, < 400) instead of $response->isRedirect() (201, 301, 302, 303, 307, 308):

if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {

Thank you,
Ben

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0