madrob commented on code in PR #2496:
URL: https://github.com/apache/solr/pull/2496#discussion_r1626818483


##########
solr/core/src/java/org/apache/solr/handler/api/V2ApiUtils.java:
##########
@@ -87,13 +88,14 @@ public static void squashIntoNamedListWithoutHeader(
     squashObjectIntoNamedList(destination, toSquash, true);
   }
 
-  public static String getMediaTypeFromWtParam(
-      SolrQueryRequest solrQueryRequest, String defaultMediaType) {
-    final String wtParam = solrQueryRequest.getParams().get(WT);
-    if (wtParam == null) return "application/json";
+  public static String getMediaTypeFromWtParam(SolrParams params, String 
defaultMediaType) {
+    final String wtParam = params.get(WT);
+    if (StrUtils.isBlank(wtParam)) return defaultMediaType;
 
     // The only currently-supported response-formats for JAX-RS v2 endpoints.
     switch (wtParam) {
+      case "json":

Review Comment:
   This feels like something that should be pluggable and stored in a Map 
instead of a switch. Thinking about what if somebody wants cbor or whatever.



##########
solr/core/src/test/org/apache/solr/handler/api/V2ApiUtilsTest.java:
##########
@@ -36,4 +40,21 @@ public void testReadsDisableV2ApiSysprop() {
     assertFalse(
         "v2 API should be disabled if sysprop explicitly disables it", 
V2ApiUtils.isEnabled());
   }
+
+  @Test
+  public void testConvertsWtToMediaTypeString() {
+    assertEquals(
+        "someDefault",
+        V2ApiUtils.getMediaTypeFromWtParam(new ModifiableSolrParams(), 
"someDefault"));
+
+    var params = new ModifiableSolrParams();
+    params.add("wt", "json");
+    assertEquals(MediaType.APPLICATION_JSON, 
V2ApiUtils.getMediaTypeFromWtParam(params, null));
+
+    params.set("wt", "xml");
+    assertEquals(MediaType.APPLICATION_XML, 
V2ApiUtils.getMediaTypeFromWtParam(params, null));
+
+    params.set("wt", "javabin");
+    assertEquals(BINARY_CONTENT_TYPE_V2, 
V2ApiUtils.getMediaTypeFromWtParam(params, null));
+  }

Review Comment:
   params.set(wt, foo)



-- 
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]

Reply via email to