Skip to content

ContentNegotiatingViewResolver [SPR-10761] #15387

@spring-projects-issues

Description

@spring-projects-issues

Jarrod Cuzens opened SPR-10761 and commented

We had an issue where we had a RequestMapping that produces="application/json". Our client was not sending an "Accept" header and as a result did not see the json response (received a 404) since the only thing that this method is supposed to produce is JSON.

According to the w3c spec if an "Accept" header is not supplied the default should be "*/*" and if this had been provided then the client would have received the "application/json" response as intended.

The ContentNegotiatingViewResolver does support a defaultMediaType but providing "*/*" does nothing because by the time that the code reaches this default it has already passed the earlier part of the code that looks at the "producibles" to know that it should reply with "application/json".

I would propose refactoring the ContentNegotiatingViewResolver such that when the accept header is not provided and a defaultMediaType is specified that the accept header should be considered to be "*/*" so that it can match the produces attribute.


Affects: 3.1.3

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions