epugh commented on code in PR #4080:
URL: https://github.com/apache/solr/pull/4080#discussion_r2733478585
##########
solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java:
##########
@@ -200,12 +201,55 @@ default QueryResponseWriter getResponseWriter() {
// it's weird this method is here instead of SolrQueryResponse, but it's
practical/convenient
SolrCore core = getCore();
String wt = getParams().get(CommonParams.WT);
+
+ if (wt == null || wt.isEmpty()) {
+ // Fall back to Accept header if wt parameter is not provided
+ wt = getWtFromAcceptHeader();
+ }
+
+ QueryResponseWriter writer;
if (core != null) {
- return core.getQueryResponseWriter(wt);
+ writer = core.getQueryResponseWriter(wt);
} else {
- return SolrCore.DEFAULT_RESPONSE_WRITERS.getOrDefault(
- wt, SolrCore.DEFAULT_RESPONSE_WRITERS.get("standard"));
+ writer = SolrCore.DEFAULT_RESPONSE_WRITERS.get(wt);
+ }
+ if (writer == null) {
+ throw new SolrException(
+ SolrException.ErrorCode.SERVER_ERROR, "Unknown response writer type:
" + wt);
+ }
+ return writer;
+ }
+
+ /**
+ * Maps the HTTP Accept header to a wt parameter value. Returns "json" as
default if no Accept
+ * header is present or if the content type is not recognized.
+ *
+ * <p>This is a quick implmentation, but it's not pluggable. For example,
how do we support CBOR
+ * without modifying this. In V2ApiUtils.getMediaTypeFromWtParam() we do the
same basic thing. i
+ * also dont' see cbor.
+ *
+ * @return the wt parameter value corresponding to the Accept header, or
"json" as default
+ */
+ default String getWtFromAcceptHeader() {
+ HttpSolrCall httpSolrCall = getHttpSolrCall();
+ if (httpSolrCall != null) {
+ String acceptHeader = httpSolrCall.getReq().getHeader("Accept");
+ if (acceptHeader != null && !acceptHeader.isEmpty()) {
+ // Handle multiple accept types (e.g., "application/json, text/plain")
+ // by checking if the header contains specific content types
+ if (acceptHeader.contains("application/xml") ||
acceptHeader.contains("text/xml")) {
+ return "xml";
+ } else if (acceptHeader.contains("application/json")) {
+ return CommonParams.JSON;
+ } else if (acceptHeader.contains("application/javabin")
+ || acceptHeader.contains("application/vnd.apache.solr.javabin")) {
+ return CommonParams.JAVABIN;
+ }
+ // For "*/*" or unrecognized types, fall through to default
+ }
}
+ // Default to JSON when no Accept header or unrecognized content type
+ return CommonParams.JSON;
Review Comment:
i remain ambivalent about these... maybe okay? I mean, if I do a curl
command don't provide wt=json OR the content types, maybe okay? It might be a
perfectly nice thign for our users...
##########
solr/core/src/java/org/apache/solr/servlet/SolrRequestParsers.java:
##########
@@ -68,11 +68,11 @@ public class SolrRequestParsers {
private static final Logger log =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
// Should these constants be in a more public place?
- public static final String MULTIPART = "multipart";
- public static final String FORMDATA = "formdata";
- public static final String RAW = "raw";
- public static final String SIMPLE = "simple";
- public static final String STANDARD = "standard";
+ // public static final String MULTIPART = "multipart";
+ // public static final String FORMDATA = "formdata";
Review Comment:
so many unused statics!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]