Repository navigation
Description
Background
After #16237, two policies negotiate a response:
- Grails' negotiation picks the format that selects a renderer, a view or a
withFormatblock:response.format,request.format(fromContent-Type),withFormatand the formatrespondwrites in. It chooses among the typesgrails.mime.typesconfigures, with rules of its own:- the
Acceptheader ignored for the user agentsgrails.mime.disable.accept.header.userAgentslists, and for XHR requests unlessgrails.mime.disable.accept.header.userAgentsXhris set, text/xmlandapplication/xmlmerged intoxml, and+xmltypes preferred to it at equal quality,- the problem types of RFC 9457 read as the
jsonandxmlformats, params.formatand URL extensions, and the fallback to the first configured type.
- the
- Spring MVC's
ContentNegotiationManagerpicks the media type among those its message converters can write. Since Modernize MIME negotiation and serialization for Spring Boot 4.1 #16237 it decides how Spring MVC writes problems, the values of actions it writes (a returnedResponseEntity,ProblemDetailand so on, and, withgrails.controllers.responseBody, the values of@ResponseBodyactions), and the JSONrespondwrites through Spring MVC.
The parsing is already shared: DefaultAcceptHeaderParser reads each media type with Spring's MediaType.parseMediaType, and the Grails data formats are registered with Spring as format aliases. What remains is the two policies, which can answer the same request differently. A browser's */* is one example; a client of a Grails view and of a Spring-written value of the same action is another.
Proposal
Grails 9, opt-in. Add a setting that resolves request.format, response.format, withFormat and respond's format through Spring MVC's ContentNegotiationManager, mapping the media type it selects back to the Grails format grails.mime.types gives it. For each Grails rule above, decide whether to:
- keep it, as a strategy of Spring's manager that applies to Grails actions only,
- port it to Spring's configuration, such as
spring.mvc.contentnegotiation.*, or - drop it, with an entry in the upgrade guide.
A comparison spec. Run a matrix of requests through both policies and record every answer that differs. The matrix covers Accept headers with qualities, wildcards and +json/+xml types, browser and XHR user agents, ?format= and URL extensions, Content-Type for request.format, and several grails.mime.types configurations. That record is the evidence for the default, and the list the upgrade guide gives.
Grails 10, the default. Make the setting the default with the other migration settings Grails 10 makes the default, such as grails.web.rendering.json.spring and grails.controllers.responseBody: once most JSON bodies go through Spring MVC, two policies that can answer a request differently cost more than the changes the comparison spec records.
Constraints
GrailsContentNegotiationStrategystays out of the context as a SpringContentNegotiationStrategybean, which Spring Security adopts.- The negotiation of Spring MVC endpoints (
@RestController,produces,spring.mvc.contentnegotiation.*) is unchanged. - The Grails 9 behaviour stays the default until the setting's default changes, as for the other migration settings in
grails.config.Settings.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
Resolve Grails formats through Spring MVC's content negotiation (#16698)