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

SOLR-10998: Obey 'Accept' header in v2 APIs #3262

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gerlowskija
Copy link
Contributor

'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:

  • tests
  • CHANGES.txt entry

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, then Accept 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:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

'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:
  - tests
  - CHANGES.txt entry
@epugh
Copy link
Contributor

epugh commented Mar 13, 2025

This is some nice alignment with normal web expectations..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants