epugh commented on code in PR #4946:
URL: https://github.com/apache/solr/pull/4946#discussion_r4109325282


##########
solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java:
##########
@@ -163,6 +165,39 @@ protected ModifiableSolrParams initializeSolrParams(
     return params;
   }
 
+  // ResponseParser#getContentTypes() is contractually stable per parser (same 
Set instance every
+  // call), so the 'Accept' header derived from it is cacheable; this avoids 
rebuilding the same
+  // joined string on every request. Bounded in size by the number of distinct 
ResponseParser
+  // content-type sets in the JVM, which is small and fixed.
+  private static final Map<Collection<String>, String> ACCEPT_HEADER_CACHE =
+      new ConcurrentHashMap<>();
+
+  /**
+   * The 'Accept' header value that requests the response format {@code 
parserToUse} can read, or
+   * {@code null} if the parser doesn't care (in which case no 'Accept' header 
is added, and the
+   * server picks its own default -- currently JSON for v2 APIs).
+   */
+  protected static String acceptHeaderFor(ResponseParser parserToUse) {
+    final Collection<String> contentTypes = parserToUse.getContentTypes();
+    if (contentTypes.isEmpty()) {
+      return null;
+    }
+    return ACCEPT_HEADER_CACHE.computeIfAbsent(contentTypes, ct -> 
String.join(", ", ct));
+  }
+
+  /** Case-insensitive check for whether {@code headers} already specifies 
{@code name}. */
+  protected static boolean hasHeader(Map<String, String> headers, String name) 
{

Review Comment:
   it so wereid about the case snsitivity thing, and we don' have anything 
better?



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