Description
Symfony version(s) affected: since 4.4.0
Description
Since #32344 the Content-Type
is set on text/plain
if the client request does only accept text/plain
. This is an issue as the symfony http cache and varnish will also cache the Content-Type
. So if a bot for example is the first one requesting the page it will get text/plain
when now a normal user request the page in the browser he will also get text/plain
and see the source code instead of a rendered html page.
How to reproduce
Have a symfony http cache or varnish in front:
First request:
curl -XGET "http://127.0.0.1:8000/?v=text-header" -H "accept: text/plain"
# or a more strange error a xml:
curl -XGET "http://127.0.0.1:8000/?v=xml-header" -H "accept: application/xml"
Now visit the page in a our browser:
- https://127.0.0.1:8000/?v=text-header (will show source code as it will return text/plain)
- https://127.0.0.1:8000/?v=xml-header (will show parse error as html is not valid xml)
The page will not be rendered as the Content-Type
header is not text/html
.
Possible Solution
I know I could set a Vary header but I think this behaviour should be reverted as its very tricky why you see now the source code of a page not its rendered html. Think this behaviour should only be changed in a major version.