Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

RedirectResponse is sent with invalid content-type when route has non-html default format #54434

Copy link
Copy link
Closed
@Seldaek

Description

@Seldaek
Issue body actions

Symfony version(s) affected

5.x.x, probably even earlier

Description

When a route has a default format set to smth else than html, and a redirect happens, the response format gets set on the redirect response incorrectly (because RedirectResponse always has html as content)

This isn't a huge problem in practice as the browser typically does not render this intermediate page's content, but it is nonetheless incorrect.

How to reproduce

#[Route('/test', name: 'test', defaults: ['_format' => 'json'])]
public function testAction()
{
        return $this->redirect('/test2');
}

Load /test, check the response headers of the 302:

HTTP/1.1 302 Found
Content-Type: application/json
Location: /test2
[...]

If the _format=>json is removed from the Route, then it uses the correct default:

Content-Type: text/html; charset=UTF-8

Possible Solution

Perhaps the _format response listener should not mess with RedirectResponse instances?

Additional Context

No response

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.