Repository navigation
Gh6743 offer QUERY in the HTTP Request method list - #6854
Conversation
milamberspace
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Adding QUERY to the method list is useful, and the change is consistent with how SEARCH/MKCALENDAR were added.
One thing worth stating clearly in the PR/changelog: sending a QUERY request already worked on master with both HttpClient4 and HttpClient5:
- HC4 routes any RFC 7230 token method through
HttpWebdav(HttpWebdav.isWebdavMethod,HTTPHC4Impl#createHttpRequest), which is entity-enclosing, so the body is sent; - HC5 builds a generic
HttpUriRequestBase(method, uri).
METHODLIST is only consumed by getValidMethodsAsArray(), i.e. the GUI Method combo box. So the effective change of this PR is "offer QUERY in the GUI". As a consequence, the new HttpQueryTest also passes with the production change reverted (I checked locally), so it does not cover what the PR changes.
Requested changes
- Test the actual change and cover HC5 as well. HTTP module tests use WireMock and parameterize over implementations (see
HttpSamplerTest.kt,TestDecompression#implementations). Below is a version I ran locally against this branch: all cases pass (HC4/HC5 send the body for both raw and form-encoded arguments; the Java implementation fails withProtocolException: Invalid HTTP method: QUERY, as expected sinceHttpURLConnectionrejects unknown methods):
@WireMockTest
class TestHttpQuery extends JMeterTestCase {
private static HTTPSamplerProxy querySampler(String impl, WireMockRuntimeInfo server) {
HTTPSamplerProxy sampler = new HTTPSamplerProxy(impl);
sampler.setProtocol("http");
sampler.setDomain("localhost");
sampler.setPort(server.getHttpPort());
sampler.setPath("/search");
sampler.setMethod(HTTPConstants.QUERY);
sampler.setConnectTimeout("5000");
sampler.setResponseTimeout("5000");
return sampler;
}
@Test
void queryIsOfferedInMethodList() {
assertTrue(Arrays.asList(HTTPSamplerBase.getValidMethodsAsArray()).contains(HTTPConstants.QUERY));
}
@ParameterizedTest
@ValueSource(strings = {HTTPSamplerFactory.IMPL_HTTP_CLIENT4, HTTPSamplerFactory.IMPL_HTTP_CLIENT5})
void querySendsRawBody(String impl, WireMockRuntimeInfo server) {
server.getWireMock().register(request("QUERY", urlEqualTo("/search"))
.willReturn(aResponse().withStatus(200).withBody("OK")));
HTTPSamplerProxy sampler = querySampler(impl, server);
sampler.setPostBodyRaw(true);
sampler.addNonEncodedArgument("", "{\"q\":\"jmeter\"}", "");
SampleResult res = sampler.sample();
assertTrue(res.isSuccessful(), res.getResponseMessage());
server.getWireMock().verifyThat(1, requestedFor("QUERY", urlEqualTo("/search"))
.withRequestBody(equalTo("{\"q\":\"jmeter\"}")));
}
@ParameterizedTest
@ValueSource(strings = {HTTPSamplerFactory.IMPL_HTTP_CLIENT4, HTTPSamplerFactory.IMPL_HTTP_CLIENT5})
void querySendsFormParameters(String impl, WireMockRuntimeInfo server) {
server.getWireMock().register(request("QUERY", urlEqualTo("/search"))
.willReturn(aResponse().withStatus(200)));
HTTPSamplerProxy sampler = querySampler(impl, server);
sampler.addArgument("a", "1");
sampler.addArgument("b", "x y");
SampleResult res = sampler.sample();
assertTrue(res.isSuccessful(), res.getResponseMessage());
server.getWireMock().verifyThat(1, requestedFor("QUERY", urlEqualTo("/search"))
.withRequestBody(equalTo("a=1&b=x+y")));
}
@Test
void javaImplementationRejectsQuery(WireMockRuntimeInfo server) {
SampleResult res = querySampler(HTTPSamplerFactory.IMPL_JAVA, server).sample();
assertFalse(res.isSuccessful());
}
}-
Changelog: please add an entry in
xdocs/changes.xmlunder HTTP Samplers and Test Script Recorder, e.g.<li><issue>6743</issue><pr>6854</pr>Add <code>QUERY</code> to the list of HTTP Request methods</li>. -
Documentation: see the inline comment,
QUERYis not a WebDav method.
Minor / follow-ups (non-blocking)
- Users who already worked around this with
httpsampler.user_defined_methods=QUERYwill now seeQUERYtwice in the combo box (the property values are appended without de-duplication). Could be worth de-duplicating, or at least mentioning in the changelog. - HC4's
StandardHttpRequestRetryHandlerdoes not treatQUERYas idempotent; irrelevant with the defaulthttpclient4.retrycount=0, just noting it.
orimarko
left a comment
There was a problem hiding this comment.
fix code review and test
milamberspace
left a comment
There was a problem hiding this comment.
Thanks for the quick update, the new test and the documentation change look good (the 6 test cases pass locally).
CI is currently red because of style checks only, plus a small markup issue in the changelog:
- Checkstyle (
AvoidStarImport):import static com.github.tomakehurst.wiremock.client.WireMock.*;must be replaced by explicit imports. - Autostyle: the import order should be
static,java.,org,com. Running./gradlew autostyleApplyfixes it automatically. - changes.xml: the
</li>is closed in the middle of the sentence (see inline comment). - Minor: the class body is indented with 8 spaces instead of 4, and there are two blank lines after the imports.
Running ./gradlew --quiet classes style locally before pushing should catch all of this. Once CI is green, this looks ready to me.
|
|
||
| package org.apache.jmeter.protocol.http.sampler; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.*; |
There was a problem hiding this comment.
Checkstyle rejects star imports (AvoidStarImport), please use explicit imports:
| import static com.github.tomakehurst.wiremock.client.WireMock.*; | |
| import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | |
| import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; | |
| import static com.github.tomakehurst.wiremock.client.WireMock.request; | |
| import static com.github.tomakehurst.wiremock.client.WireMock.requestedFor; | |
| import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
Then ./gradlew autostyleApply will fix the order of the remaining imports.
| <li><issue>6743</issue><pr>6854</pr>Add <code>QUERY</code> to the list of HTTP Request methods</li>. If <code>httpsampler.user_defined_methods</code> already contains | ||
| <code>QUERY</code>, it will appear twice in the method list. |
There was a problem hiding this comment.
The </li> closes the item mid-sentence, so the second sentence ends up directly inside the <ul>:
| <li><issue>6743</issue><pr>6854</pr>Add <code>QUERY</code> to the list of HTTP Request methods</li>. If <code>httpsampler.user_defined_methods</code> already contains | |
| <code>QUERY</code>, it will appear twice in the method list. | |
| <li><issue>6743</issue><pr>6854</pr>Add <code>QUERY</code> to the list of HTTP Request methods. If <code>httpsampler.user_defined_methods</code> already contains | |
| <code>QUERY</code>, it will appear twice in the method list.</li> |
milamberspace
left a comment
There was a problem hiding this comment.
Thanks for the quick follow-ups! All review points are addressed and CI is green. LGTM.
I will fix the remaining indentation of TestHttpQuery (4 spaces instead of 8) when squash-merging, no need for another round.
Generated-by: Claude Code 2.1.330 (Claude Opus 5.5)
Description
Add QUERY option to HTTP Request methods
Motivation and Context
Fix issue
#6743
[feature] Add HTTP QUERY method, formalized as RFC 10008 in June 2026
#6743
How Has This Been Tested?
Checked UI: execute runGui and submitted QUERY request with body and checked it in listener
Added unit test and tested
Added QUERY method to HTTP Request documentation
Screenshots (if appropriate):
Types of changes
Checklist: