Skip to content

Gh6743 offer QUERY in the HTTP Request method list - #6854

Merged
milamberspace merged 7 commits into
apache:masterfrom
orimarko:gh6743-add-http-query
Nov 21, 2026
Merged

milamberspace merged 7 commits into
apache:masterfrom
orimarko:gh6743-add-http-query

Conversation

@orimarko

@orimarko orimarko commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.

@milamberspace milamberspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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 with ProtocolException: Invalid HTTP method: QUERY, as expected since HttpURLConnection rejects 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());
    }
}
  1. Changelog: please add an entry in xdocs/changes.xml under 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>.

  2. Documentation: see the inline comment, QUERY is not a WebDav method.

Minor / follow-ups (non-blocking)

  • Users who already worked around this with httpsampler.user_defined_methods=QUERY will now see QUERY twice 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 StandardHttpRequestRetryHandler does not treat QUERY as idempotent; irrelevant with the default httpclient4.retrycount=0, just noting it.

@orimarko orimarko changed the title Gh6743 add http query Gh6743 offer QUERY in the HTTP Request method list Nov 20, 2026

@orimarko orimarko left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix code review and test

@milamberspace milamberspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Checkstyle (AvoidStarImport): import static com.github.tomakehurst.wiremock.client.WireMock.*; must be replaced by explicit imports.
  2. Autostyle: the import order should be static, java., org, com. Running ./gradlew autostyleApply fixes it automatically.
  3. changes.xml: the </li> is closed in the middle of the sentence (see inline comment).
  4. 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.*;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkstyle rejects star imports (AvoidStarImport), please use explicit imports:

Suggested change
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.

Comment thread xdocs/changes.xml Outdated
Comment on lines +102 to +103
<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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The </li> closes the item mid-sentence, so the second sentence ends up directly inside the <ul>:

Suggested change
<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 milamberspace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@milamberspace
milamberspace merged commit 6e9cbaf into apache:master Nov 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants