Problem/Motivation
After upgrade to Drupal 10.5.6 the following Exception occurs for ajax-requests with Content-type: "application/json".
UnsupportedMediaTypeHttpException: No route found that matches "Content-Type: application/json"
Steps to reproduce
Install Drupal 10.5.6 and send ajax-request with "Content-Type: application/json" header.
Proposed resolution
It happens because `rest_entity_recursive` module registers a new format "json_recursive" that automatically will be applied for requests with "Content-Type: application/json" header (https://git.drupalcode.org/project/rest_entity_recursive/-/blob/2.x/src/...). What is a source of this problem.
It manages with http-foundation library and the logic of "format detector" has been updated 3 weeks ago (https://github.com/symfony/http-foundation/commit/ee93009480be472b3201ca...).
It always returned "1st matched" format from the whole list unless these changes were applied. After that upgrade it returns "last matched" instead.
Only one fix that should be applied - change expected "Content-type" for "application/json" format. Use "application/recursive-json" instead of "application/json".
It's important to bear in mind that a certain "Content-type" should be used only once: "application/json" is already allocated for "json" format and it shouldn't be overridden by other formats unless we really want to override it (use a different handler).
Right now to use "json_recursive" format, a user should pass "_format=json_recursive" in query string. With this fix - "Content-type: application/json-recursive" header will do the same and "json_recursive" format will not be used for requests with "Content-type: application/json" format.
Issue fork rest_entity_recursive-3558456
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
beloglazov91Comment #3
beloglazov91Comment #5
beloglazov91Comment #6
pavel.bulatThanks for the fix @beloglazov91
Comment #8
beloglazov91Comment #9
beloglazov91