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.

Command icon 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

beloglazov91 created an issue. See original summary.

beloglazov91’s picture

Issue summary: View changes
beloglazov91’s picture

Issue summary: View changes

beloglazov91’s picture

Status: Active » Needs review
pavel.bulat’s picture

Status: Needs review » Fixed

Thanks for the fix @beloglazov91

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

beloglazov91’s picture

Title: UnsupportedMediaTypeHttpException: No route found that matches "Content-Type: application/json" » Content-type header "application/json" shouldn't be used for json_recursive
beloglazov91’s picture

Status: Fixed » Closed (fixed)