This is an automated email from the ASF dual-hosted git repository.
jdyer pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new bdd92ff5b2b SOLR-17589 First use of PUT/POST request with
HttpJdkSolrClient generates error log entry on solr server due to initial HEAD
request (#2926)
bdd92ff5b2b is described below
commit bdd92ff5b2b04126f7efb49d2fd04ddb286aad4f
Author: Paul Blanchaert <[email protected]>
AuthorDate: Mon Jan 13 16:58:55 2025 +0100
SOLR-17589 First use of PUT/POST request with HttpJdkSolrClient generates
error log entry on solr server due to initial HEAD request (#2926)
---
solr/CHANGES.txt | 2 ++
.../apache/solr/client/solrj/impl/HttpJdkSolrClient.java | 3 ++-
.../solr/client/solrj/impl/HttpJdkSolrClientTest.java | 15 +++++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
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 @@ public class HttpJdkSolrClient extends HttpSolrClientBase {
}
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 class HttpJdkSolrClientTest extends
HttpSolrClientTestBase {
}
}
+ @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