Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16274: HEAD request for managed resource returns 500 Server Error (#1140)

Kevin Risden6869ec97c7a5
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 28d82a816a8..0ba100e6c5a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -82,6 +82,8 @@ Bug Fixes
* SOLR-10918: Fix IntPointField hashing for HLL (Houston Putman)
+* SOLR-16274: HEAD request for managed resource returns 500 Server Error (Kevin Risden)
+
Build
---------------------
* Upgrade forbiddenapis to 3.4 (Uwe Schindler)
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index b8894648262..cf6e7d51cc9 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -2938,6 +2938,7 @@ public class SolrCore implements SolrInfoBean, Closeable {
SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp) {
// TODO should check that responseHeader has not been replaced by handler
NamedList<Object> responseHeader = rsp.getResponseHeader();
+ if (responseHeader == null) return;
final int qtime = (int) (req.getRequestTimer().getTime());
int status = 0;
Exception exception = rsp.getException();
diff --git a/solr/core/src/java/org/apache/solr/rest/RestManager.java b/solr/core/src/java/org/apache/solr/rest/RestManager.java
index b7e7ac26d9c..d83f6bc7363 100644
--- a/solr/core/src/java/org/apache/solr/rest/RestManager.java
+++ b/solr/core/src/java/org/apache/solr/rest/RestManager.java
@@ -355,10 +355,7 @@ public class RestManager {
}
private void doHead(ManagedEndpoint managedEndpoint) {
- // Setting the response to blank clears the content out,
- // however it also means the Content-Length HTTP Header is set to 0
- // which isn't compliant with the specification of how HEAD should work,
- // it should instead return the length of the content if you did a GET.
+ // Setting the response to blank clears the content out.
NamedList<Object> blank = new SimpleOrderedMap<>();
managedEndpoint.getSolrResponse().setAllValues(blank);
}
diff --git a/solr/core/src/test/org/apache/solr/rest/TestRestManager.java b/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
index 2afba9d8a9c..a95bd3d3edd 100644
--- a/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
+++ b/solr/core/src/test/org/apache/solr/rest/TestRestManager.java
@@ -40,6 +40,8 @@ public class TestRestManager extends SolrRestletTestBase {
public void testRestManagerEndpoints() throws Exception {
// relies on these ManagedResources being activated in the schema-rest.xml used by this test
assertJQ("/schema/managed", "/responseHeader/status==0");
+ assertHead("/schema/managed", 200);
+
/*
* TODO: can't assume these will be here unless schema-rest.xml includes these declarations
*
@@ -64,9 +66,11 @@ public class TestRestManager extends SolrRestletTestBase {
"/schema/managed",
"/managedResources/[0]/class=='org.apache.solr.rest.schema.analysis.ManagedWordSetResource'",
"/managedResources/[0]/resourceId=='/schema/analysis/protwords/english'");
+ assertHead("/schema/managed", 200);
// query the resource we just created
assertJQ(newEndpoint, "/wordSet/managedList==[]");
+ assertHead(newEndpoint, 200);
// add some words to this new word list manager
assertJPut(
@@ -74,14 +78,16 @@ public class TestRestManager extends SolrRestletTestBase {
Utils.toJSONString(Arrays.asList("this", "is", "a", "test")),
"/responseHeader/status==0");
+ // make sure the default is serialized even if not specified
assertJQ(
newEndpoint,
"/wordSet/managedList==['a','is','test','this']",
- "/wordSet/initArgs=={'ignoreCase':false}"); // make sure the default is serialized even if
- // not specified
+ "/wordSet/initArgs=={'ignoreCase':false}");
+ assertHead(newEndpoint, 200);
// Test for case-sensitivity - "Test" lookup should fail
assertJQ(newEndpoint + "/Test", "/responseHeader/status==404");
+ assertHead(newEndpoint + "/Test", 404);
// Switch to case-insensitive
assertJPut(
@@ -89,6 +95,7 @@ public class TestRestManager extends SolrRestletTestBase {
// Test for case-insensitivity - "Test" lookup should succeed
assertJQ(newEndpoint + "/Test", "/responseHeader/status==0");
+ assertHead(newEndpoint + "/Test", 200);
// Switch to case-sensitive - this request should fail: changing ignoreCase from true to false
// is not permitted
@@ -103,6 +110,7 @@ public class TestRestManager extends SolrRestletTestBase {
"/response/lst[@name='wordSet']/arr[@name='managedList']/str[2]='is'",
"/response/lst[@name='wordSet']/arr[@name='managedList']/str[3]='test'",
"/response/lst[@name='wordSet']/arr[@name='managedList']/str[4]='this'");
+ assertHead(newEndpoint + "?wt=xml", 200);
// delete the one we created above
assertJDelete(newEndpoint, "/responseHeader/status==0");
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
index 589698e3d0c..29de96c7ac8 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
@@ -152,6 +152,12 @@ public abstract class RestTestBase extends SolrJettyTestBase {
}
}
+ public static void assertHead(String request, int expectedStatusCode) throws IOException {
+ String response = restTestHarness.head(request);
+ assertTrue(response.contains("HTTP/1.1 " + expectedStatusCode));
+ assertTrue(response.contains("Content-Length: 0"));
+ }
+
/**
* Makes a query request and returns the JSON string response
*
diff --git a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
index 2433b421782..6935a04cd11 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/RestTestHarness.java
@@ -25,6 +25,7 @@ import javax.xml.xpath.XPathExpressionException;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
@@ -106,6 +107,20 @@ public class RestTestHarness extends BaseTestHarness implements Closeable {
return getResponse(new HttpGet(getAdminURL() + request));
}
+ /**
+ * Processes a HEAD request using a URL path (with no context path) + optional query params and
+ * returns the response content.
+ *
+ * @param request The URL path and optional query params
+ * @return The response to the HEAD request
+ */
+ public String head(String request) throws IOException {
+ HttpHead httpHead = new HttpHead(getBaseURL() + request);
+ return httpClient
+ .execute(httpHead, HttpClientUtil.createNewHttpClientRequestContext())
+ .toString();
+ }
+
/**
* Processes a PUT request using a URL path (with no context path) + optional query params, e.g.
* "/schema/fields/newfield", PUTs the given content, and returns the response content.