SOLR-10998: Obey 'Accept' header in v2 APIs #3262
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
'wt' takes precedence if specified for now, if not provided Solr (through our use of Jersey) will pick a response format in keeping with the specified 'Accept' header.
JSON responses remains the "default" if neither 'wt' nor an "Accept" header are specified.
Still needed:
https://issues.apache.org/jira/browse/SOLR-10998
Description
The HTTP spec defines an "Accept" header that users can provide to specify the response format (or formats, plural) that they're willing to "accept" in a response. This is part of the HTTP specs support for "content negotiation" more generally.
Solr today doesn't support this, and opts to have users specify their response format in a "wt" (i.e. "writer type") query-parameter. We should obey "Accept" headers, when they are provided.
Solution
This PR modifies Solr to obey "Accept" headers on v2 API requests, unless an overriding "wt" parameter is also provided. Jersey (which is used for v2 requests) actually obeys the "Accept" header out of the box, but a bug in our
MediaTypeOverridingFilter
(which implements the 'wt' override) was causing the value of "Accept" to be ignored altogether.With this change, the order of precedence for v2 APIs is:
wt
parameter, thenAccept
header, and lastly "JSON" is used as a fallback/default.Tests
TBD - still need tests here to ensure that v2 APIs obey common 'wt' and Accept header values.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.