SOLR-14946: fix responseHeader returned in resp with omitHeader=true (#2029)

* This occurs when BinaryResponseWriter#getParsedResponse is called as
  it doesn't check for omitHeader.
This commit is contained in:
S N Munendra 2020-10-30 18:50:18 +05:30 committed by GitHub
parent 57729c9aca
commit f3fdd9b90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -160,6 +160,8 @@ Optimizations
Bug Fixes Bug Fixes
--------------------- ---------------------
* SOLR-14946: Fix responseHeader being returned in response when omitHeader=true and EmbeddedSolrServer is used
as the client (Munendra S N)
* SOLR-14940: ReplicationHandler memory leak through SolrCore.closeHooks with unstable ZK connection. (Anver Sotnikov, Mike Drob) * SOLR-14940: ReplicationHandler memory leak through SolrCore.closeHooks with unstable ZK connection. (Anver Sotnikov, Mike Drob)

View File

@ -195,6 +195,9 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static NamedList<Object> getParsedResponse(SolrQueryRequest req, SolrQueryResponse rsp) { public static NamedList<Object> getParsedResponse(SolrQueryRequest req, SolrQueryResponse rsp) {
try { try {
if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) {
rsp.removeResponseHeader();
}
Resolver resolver = new Resolver(req, rsp.getReturnFields()); Resolver resolver = new Resolver(req, rsp.getReturnFields());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();

View File

@ -36,6 +36,7 @@ import org.apache.solr.common.util.ByteUtils;
import org.apache.solr.common.util.JavaBinCodec; import org.apache.solr.common.util.JavaBinCodec;
import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.NamedList;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.BinaryResponseWriter.Resolver; import org.apache.solr.response.BinaryResponseWriter.Resolver;
import org.apache.solr.search.SolrReturnFields; import org.apache.solr.search.SolrReturnFields;
import org.apache.solr.util.SimplePostTool; import org.apache.solr.util.SimplePostTool;
@ -119,6 +120,21 @@ public class TestBinaryResponseWriter extends SolrTestCaseJ4 {
req.close(); req.close();
} }
public void testOmitHeader() throws Exception {
SolrQueryRequest req = req("q", "*:*", "omitHeader", "true");
SolrQueryResponse rsp = h.queryAndResponse(null, req);
NamedList<Object> res = BinaryResponseWriter.getParsedResponse(req, rsp);
assertNull(res.get("responseHeader"));
req.close();
req = req("q", "*:*");
rsp = h.queryAndResponse(null, req);
res = BinaryResponseWriter.getParsedResponse(req, rsp);
assertNotNull(res.get("responseHeader"));
req.close();
}
public void testResolverSolrDocumentPartialFields() throws Exception { public void testResolverSolrDocumentPartialFields() throws Exception {
LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*", LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*",
"fl", "id,xxx,ddd_s"); "fl", "id,xxx,ddd_s");