From f3fdd9b90b8e4af4c62708c1cd28a00347c1416e Mon Sep 17 00:00:00 2001 From: S N Munendra Date: Fri, 30 Oct 2020 18:50:18 +0530 Subject: [PATCH] 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. --- solr/CHANGES.txt | 2 ++ .../solr/response/BinaryResponseWriter.java | 3 +++ .../solr/response/TestBinaryResponseWriter.java | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 48bd9a819c0..c56a0866cd3 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -160,6 +160,8 @@ Optimizations 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) diff --git a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java index a78a1342295..496cde2a0a0 100644 --- a/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/BinaryResponseWriter.java @@ -195,6 +195,9 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { @SuppressWarnings("unchecked") public static NamedList getParsedResponse(SolrQueryRequest req, SolrQueryResponse rsp) { try { + if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) { + rsp.removeResponseHeader(); + } Resolver resolver = new Resolver(req, rsp.getReturnFields()); ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/solr/core/src/test/org/apache/solr/response/TestBinaryResponseWriter.java b/solr/core/src/test/org/apache/solr/response/TestBinaryResponseWriter.java index e80b28c02cb..27f1a747cd8 100644 --- a/solr/core/src/test/org/apache/solr/response/TestBinaryResponseWriter.java +++ b/solr/core/src/test/org/apache/solr/response/TestBinaryResponseWriter.java @@ -36,6 +36,7 @@ import org.apache.solr.common.util.ByteUtils; import org.apache.solr.common.util.JavaBinCodec; import org.apache.solr.common.util.NamedList; import org.apache.solr.request.LocalSolrQueryRequest; +import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.response.BinaryResponseWriter.Resolver; import org.apache.solr.search.SolrReturnFields; import org.apache.solr.util.SimplePostTool; @@ -119,6 +120,21 @@ public class TestBinaryResponseWriter extends SolrTestCaseJ4 { req.close(); } + public void testOmitHeader() throws Exception { + SolrQueryRequest req = req("q", "*:*", "omitHeader", "true"); + SolrQueryResponse rsp = h.queryAndResponse(null, req); + + NamedList 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 { LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*", "fl", "id,xxx,ddd_s");