diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java index 43b446ed83b..eb9ccedb903 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java @@ -254,7 +254,8 @@ static int getMaxBytesToStorePerRequest() { HTTPConstants.UNLOCK, HTTPConstants.REPORT, HTTPConstants.MKCALENDAR, - HTTPConstants.SEARCH + HTTPConstants.SEARCH, + HTTPConstants.QUERY )); String userDefinedMethods = JMeterUtils.getPropDefault( "httpsampler.user_defined_methods", ""); diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java index 5defe6aee12..061a1081d4a 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/HTTPConstantsInterface.java @@ -67,6 +67,7 @@ public interface HTTPConstantsInterface { // CHECKSTYLE IGNORE InterfaceIsType String REPORT = "REPORT"; // $NON-NLS-1$ String MKCALENDAR = "MKCALENDAR"; // $NON-NLS-1$ String SEARCH = "SEARCH"; // $NON-NLS-1$ + String QUERY = "QUERY"; // $NON-NLS-1$ String HEADER_AUTHORIZATION = "Authorization"; // $NON-NLS-1$ String HEADER_COOKIE = "Cookie"; // $NON-NLS-1$ String HEADER_COOKIE_IN_REQUEST = "Cookie:"; // $NON-NLS-1$ diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHttpQuery.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHttpQuery.java new file mode 100644 index 00000000000..c2d5f784ae2 --- /dev/null +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHttpQuery.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jmeter.protocol.http.sampler; + +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; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Arrays; + +import org.apache.jmeter.junit.JMeterTestCase; +import org.apache.jmeter.protocol.http.util.HTTPConstants; +import org.apache.jmeter.samplers.SampleResult; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; +import com.github.tomakehurst.wiremock.junit5.WireMockTest; + +@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()); + } +} diff --git a/xdocs/changes.xml b/xdocs/changes.xml index e2350f71766..cb70f8a3e6f 100644 --- a/xdocs/changes.xml +++ b/xdocs/changes.xml @@ -99,6 +99,8 @@ Summary
HTTP Version combo box (property HTTPSampler.httpVersion) to the HTTP Request sampler and the HTTP Request Defaults, so the HTTP version can be selected per sampler instead of only globally with the httpclient.version property. An empty value keeps using that property, which now defaults to HTTP/1.1.Host header of the HTTP Header Manager without its port when that port is the default one of the URL in the HttpClient5 sampler implementation, as the HttpClient4 implementation does.HttpClient5 sampler implementation, like the HttpClient4 implementation does, instead of returning the redirect when the request carries cookies or credentials. Each redirect is sent with the cookies of the HTTP Cookie Manager and the credentials of the HTTP Authorization Manager for its own URL, the cookies the redirects set are kept in the Cookie Manager, and a Cookie or Authorization header of the HTTP Header Manager is only sent to the host of the initial URL. The number of redirects is limited by httpsampler.max_redirects, and cookies are only handled by the Cookie Manager, so none are sent without one.QUERY to the list of HTTP Request methods. If httpsampler.user_defined_methods already contains
+ QUERY, it will appear twice in the method list.HTTP/2 support for the HttpClient5 sampler implementation:
diff --git a/xdocs/usermanual/component_reference.xml b/xdocs/usermanual/component_reference.xml index 2e64ec36578..7bbce38e78a 100644 --- a/xdocs/usermanual/component_reference.xml +++ b/xdocs/usermanual/component_reference.xml @@ -272,7 +272,8 @@ https.default.protocol=SSLv3JAVA implementation). With HttpClient4 or HttpClient5, the following methods related to WebDav are
also allowed: COPY, LOCK, MKCOL, MOVE,
PROPFIND, PROPPATCH, UNLOCK, REPORT, MKCALENDAR,
- SEARCH.
+ SEARCH. The QUERY method (safe and idempotent request with a body) is also
+ available with HttpClient4 or HttpClient5; it is not supported by the JAVA implementation.
More methods can be pre-defined for the HttpClient4 by using the JMeter property
httpsampler.user_defined_methods.