Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for fixed content type in ContentNegotiationManager [SPR-15367] #19931

Closed
spring-issuemaster opened this Issue Mar 21, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Mar 21, 2017

Ryan O'Meara opened SPR-15367 and commented

ContentNegotiationConfigurer currently supports setting a default content type for all end points, or a content negotiation strategy. While useful, this can run into problems for applications with a variety of supported content types.

For example, if an application has set the default content type to "text/html", and has an end point which only supports "application/json", any calls which do not specify an accept header, or which specify "*/*" as the accept header, will receive a 406 response.

This is consistent with the documented behavior of setting the default content type, but applications such as these often would like to specify the preferred content type, as opposed to a forced default.

Such a configuration would ideally allow the above example to specify that endpoints that support "text/html" prefer to return it when no specific content type is requested, but still allow end points which do not support "text/html" to chose from among the media types they support (in the same manner as when no default content type is specified)


Affects: 4.3.3

Reference URL: #1362

Referenced from: commits f963367, 043c707, 4a89022, 49ac6d5

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 21, 2017

Ryan O'Meara commented

An example of what I'd like this to look like (attempting to be consistent with existing patterns):

public void ExampleWebConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer){
        List<MediaType> qualityOrderedMediaTypesPreferred = new ArrayList<>();
        qualityOrderedMediaTypesPreferred.add(MediaType.HTML);

        configurer.preferredContentTypes(qualityOrderedMediaTypesPreferred);
    }

}

I have successfully, in a local application, created a content negotiation strategy which replicates the desired behavior - I'm more than willing to contribute a pull request if you agree that this is a desirable feature to add (and that this is the correct way to add it)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 21, 2017

Ryan O'Meara commented

I have made a pull request (#1362) as a starting point to integrating this ability into the framework - I'm hoping it makes the intention of this issue clearer, if my explanation has failed to properly convey it :)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 27, 2017

Rossen Stoyanchev commented

Modified title, was: "Support Setting Preferred Content Type(s) in ContentNegotiationConfigurer".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.