Closed
Description
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