Skip to content

Commit

Permalink
SOLR-17589 First use of PUT/POST request with HttpJdkSolrClient gener…
Browse files Browse the repository at this point in the history
…ates error log entry on solr server due to initial HEAD request (#2926)
  • Loading branch information
Paul-Blanchaert authored and jdyer1 committed Jan 13, 2025
1 parent 11fa990 commit bdd92ff
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdd92ff

Please sign in to comment.