Skip to content

Allow ContentNegotiatingViewResolver to be strict ant return a 406 if no view found [SPR-6467] #11133

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-6467 and commented

Currently ContentNegotiatingViewResolver acts lenient as it returns null when it can not resolve any view to indicate that further ViewResolvers configured shall step in and try to resolve the view.

In cases when ContentNegotiatingViewResolver is the only resolver configured, not resolving the view should be answered with a 406 Not Acceptable status code. A quick hack I did was to add a property beStrict to CNVR an implement an inner class to return the appropriate statuscode. See applied patch.

This solves the problem at a first glance but I think it would be more clean to prevent processing of the request entirely if no valid accept header was set by using the algorithm getmediaTypes(..) in CNVR. Currently this method is not public, but I could imagine a HandlerInterceptor implementation that gets a reference to the CNVR injected and call to getMediaType(..) to decide whether to process the request at all.


Affects: 3.0 RC2

Attachments:

Issue Links:

Referenced from: commits 1cd0a97

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions