Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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", "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
2 changes: 2 additions & 0 deletions xdocs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Summary
<li><pr>6742</pr>Add the <code>HTTP Version</code> combo box (property <code>HTTPSampler.httpVersion</code>) 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 <code>httpclient.version</code> property. An empty value keeps using that property, which now defaults to <code>HTTP/1.1</code>.</li>
<li><pr>6742</pr>Send a <code>Host</code> header of the HTTP Header Manager without its port when that port is the default one of the URL in the <code>HttpClient5</code> sampler implementation, as the <code>HttpClient4</code> implementation does.</li>
<li><pr>6742</pr>Follow automatic redirects to another host in the <code>HttpClient5</code> sampler implementation, like the <code>HttpClient4</code> 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 <code>Cookie</code> or <code>Authorization</code> header of the HTTP Header Manager is only sent to the host of the initial URL. The number of redirects is limited by <code>httpsampler.max_redirects</code>, and cookies are only handled by the Cookie Manager, so none are sent without one.</li>
<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>
</ul>

<p>HTTP/2 support for the HttpClient5 sampler implementation:</p>
Expand Down
3 changes: 2 additions & 1 deletion xdocs/usermanual/component_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ https.default.protocol=SSLv3
<code>JAVA</code> implementation). With <code>HttpClient4</code> or <code>HttpClient5</code>, the following methods related to WebDav are
also allowed: <code>COPY</code>, <code>LOCK</code>, <code>MKCOL</code>, <code>MOVE</code>,
<code>PROPFIND</code>, <code>PROPPATCH</code>, <code>UNLOCK</code>, <code>REPORT</code>, <code>MKCALENDAR</code>,
<code>SEARCH</code>.
<code>SEARCH</code>. The <code>QUERY</code> method (safe and idempotent request with a body) is also
available with <code>HttpClient4</code> or <code>HttpClient5</code>; it is not supported by the <code>JAVA</code> implementation.
<p>More methods can be pre-defined for the HttpClient4 by using the JMeter property
<code>httpsampler.user_defined_methods</code>.</p>
</property>
Expand Down
Loading