Skip to content

Commit

Permalink
SOLR-17221: Http2SolrClient merges case sensitive solr params
Browse files Browse the repository at this point in the history
  • Loading branch information
831973741yy committed Jan 12, 2025
1 parent 4aae151 commit 1dc4d41
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ private Request fillContentStream(
}
} else {
// application/x-www-form-urlencoded
Fields fields = new Fields();
Fields fields = new Fields(true);
Iterator<String> iter = wparams.getParameterNamesIterator();
while (iter.hasNext()) {
String key = iter.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ protected void testQuerySetup(SolrRequest.METHOD method, ResponseParser rp) thro
String url = getBaseUrl() + DEBUG_SERVLET_PATH;
SolrQuery q = new SolrQuery("foo");
q.setParam("a", MUST_ENCODE);
q.setParam("case_sensitive_param", "lowercase");
q.setParam("CASE_SENSITIVE_PARAM", "uppercase");
Http2SolrClient.Builder b =
new Http2SolrClient.Builder(url).withDefaultCollection(DEFAULT_CORE);
if (rp != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ protected void testQuerySetup(SolrRequest.METHOD method, ResponseParser rp) thro
String url = getBaseUrl() + DEBUG_SERVLET_PATH;
SolrQuery q = new SolrQuery("foo");
q.setParam("a", MUST_ENCODE);
q.setParam("case_sensitive_param", "lowercase");
q.setParam("CASE_SENSITIVE_PARAM", "uppercase");
HttpJdkSolrClient.Builder b = builder(url);
if (rp != null) {
b.withResponseParser(rp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public void testQueryGet() throws Exception {
// param encoding
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
// case sensitive param
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
}

public void testQueryPost() throws Exception {
Expand All @@ -128,10 +133,14 @@ public void testQueryPost() throws Exception {
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
assertEquals(expectedUserAgent(), DebugServlet.headers.get("user-agent"));
assertEquals("application/x-www-form-urlencoded", DebugServlet.headers.get("content-type"));
// this validates that URI encoding has been applied - the content-length is smaller if not
assertEquals("41", DebugServlet.headers.get("content-length"));
assertEquals("103", DebugServlet.headers.get("content-length"));
}

public void testQueryPut() throws Exception {
Expand All @@ -144,9 +153,13 @@ public void testQueryPut() throws Exception {
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
assertEquals(expectedUserAgent(), DebugServlet.headers.get("user-agent"));
assertEquals("application/x-www-form-urlencoded", DebugServlet.headers.get("content-type"));
assertEquals("41", DebugServlet.headers.get("content-length"));
assertEquals("103", DebugServlet.headers.get("content-length"));
}

public void testQueryXmlGet() throws Exception {
Expand All @@ -159,6 +172,10 @@ public void testQueryXmlGet() throws Exception {
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
assertEquals(expectedUserAgent(), DebugServlet.headers.get("user-agent"));
}

Expand All @@ -172,6 +189,10 @@ public void testQueryXmlPost() throws Exception {
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
assertEquals(expectedUserAgent(), DebugServlet.headers.get("user-agent"));
assertEquals("application/x-www-form-urlencoded", DebugServlet.headers.get("content-type"));
}
Expand All @@ -186,6 +207,10 @@ public void testQueryXmlPut() throws Exception {
assertEquals(1, DebugServlet.parameters.get(CommonParams.VERSION).length);
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);
assertEquals(expectedUserAgent(), DebugServlet.headers.get("user-agent"));
assertEquals("application/x-www-form-urlencoded", DebugServlet.headers.get("content-type"));
}
Expand Down Expand Up @@ -264,6 +289,9 @@ protected void testUpdate(HttpSolrClientBase client, WT wt, String contentType,
req.add(doc);
// non-ASCII characters and curly quotes should be URI-encoded
req.setParam("a", MUST_ENCODE);
// params should be case sensitive
req.setParam("case_sensitive_param", "lowercase");
req.setParam("CASE_SENSITIVE_PARAM", "uppercase");

try {
client.request(req);
Expand All @@ -281,6 +309,10 @@ protected void testUpdate(HttpSolrClientBase client, WT wt, String contentType,
assertEquals(contentType, DebugServlet.headers.get("content-type"));
assertEquals(1, DebugServlet.parameters.get("a").length);
assertEquals(MUST_ENCODE, DebugServlet.parameters.get("a")[0]);
assertEquals(1, DebugServlet.parameters.get("case_sensitive_param").length);
assertEquals("lowercase", DebugServlet.parameters.get("case_sensitive_param")[0]);
assertEquals(1, DebugServlet.parameters.get("CASE_SENSITIVE_PARAM").length);
assertEquals("uppercase", DebugServlet.parameters.get("CASE_SENSITIVE_PARAM")[0]);

if (wt == WT.XML) {
String requestBody = new String(DebugServlet.requestBody, StandardCharsets.UTF_8);
Expand Down

0 comments on commit 1dc4d41

Please sign in to comment.