diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 83bcbf5af6e..615dba567d1 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -46,6 +46,8 @@ Other Changes * SOLR-16503: Most remaining usages of Apache HttpClient in Solr switched to Jetty HttpClient (HTTP 2). (Sanjay Dutt, David Smiley) +* SOLR-17589: Prevent error log entry on solr server due to initial HEAD request from HttpJdkSolrClient. (Paul Blanchaert via James Dyer) + ================== 9.8.0 ================== New Features --------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java index 56863babee3..32f06cf6520 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpJdkSolrClient.java @@ -402,7 +402,8 @@ private synchronized boolean maybeTryHeadRequestSync(String url) { } HttpRequest.Builder headReqB = HttpRequest.newBuilder(uriNoQueryParams) - .method("HEAD", HttpRequest.BodyPublishers.noBody()); + .method("HEAD", HttpRequest.BodyPublishers.noBody()) + .header("Content-Type", ClientUtils.TEXT_JSON); decorateRequest(headReqB, new QueryRequest()); try { httpClient.send(headReqB.build(), HttpResponse.BodyHandlers.discarding()); diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java index 07a202ccc65..0ec2ac87be0 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpJdkSolrClientTest.java @@ -594,6 +594,21 @@ public void testPing() throws Exception { } } + @Test + public void testMaybeTryHeadRequestHasContentType() throws Exception { + DebugServlet.clear(); + String url = getBaseUrl() + DEBUG_SERVLET_PATH; + try (HttpJdkSolrClient client = builder(url).build()) { + assertTrue(client.maybeTryHeadRequest(url)); + + // if https, the client won't attempt a HEAD request + if (client.headRequested) { + assertEquals("head", DebugServlet.lastMethod); + assertTrue(DebugServlet.headers.containsKey("content-type")); + } + } + } + /** * This is not required for any test, but there appears to be a bug in the JDK client where it * does not release all threads if the client has not performed any queries, even after a forced