diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index f68b03493ee..4c5bf3b5faa 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -185,6 +185,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 1127b3fd1a1..07cc7f242b1 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 @@ -392,7 +392,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 b3980ad44bc..f0880e1ae7c 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 @@ -498,6 +498,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