Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.0-beta12
Description: 

Drupal core no longer uses accept headers for routing but rather rely on a _format query parameter, because browser, (reverse) proxy and CDN support is very poor, and hence could lead to severe bugs. See #2364011: [meta] External caches mix up response formats on URLs where content negotiation is in use for more background.

This is an example to a hal_json request

Before

curl -i http://d8.dev/node/1 -H "Accept: application/hal_json"

After

curl -i http://d8.dev/node/1?_format=hal_json

This also leads to changed PHP api.
So if you want to link to a specific format you can now do that:

$url = Url::fromRoute('example_route')->setOption('query', ['_format' => 'hal_json']);
Impacts: 
Module developers

Comments

matt2000’s picture

That would be .... unfortunate. :-(

Anonymous’s picture

I can see why a query parameter was added, but removing the accept header based route is a silly idea...

kylebrowning’s picture

This is really really sad to see.

brian.reese’s picture

If others are still struggling with this, make sure you're including the underscore before '_format' in your query (I tried several times before noticing it was there!). Using basic auth, both json and hal_json requests work for me, d8 beta15

dgtlmoon’s picture

@dawehner

because browser, (reverse) proxy and CDN support is very poor, and hence could lead to severe bugs

Would be nice to link in a list of known issues..

bradjones1’s picture

This is also no longer totally true for all of Drupal core; json:api being the major exception. In fact, you will get a helpful (but still fatal) validation error from json:api when using _format, since it does not comport with the spec. (In fact, you should pass at least Accept: application/vnd.api+json when using json:api, but it's not technically required as the request format is set by virtue of the path you're accessing.

For those asking about the reasoning behind this CR, the linked issue in the summary (after the bold text) has a few good examples.