diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java index ad96efbad78..ca61d22413c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java @@ -191,25 +191,17 @@ public class HttpConnection extends AbstractConnection implements Connection params.append("&"); } - // Behave as a GET, adding the params to the path, if it's a POST with some content - if (method == HttpMethod.POST && request.getContent() != null) - method = HttpMethod.GET; - - switch (method) + // POST with no content, send parameters as body + if (method == HttpMethod.POST && request.getContent() == null) { - case GET: - { - path += "?"; - path += params.toString(); - request.path(path); - break; - } - case POST: - { - request.header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString()); - request.content(new StringContentProvider(params.toString())); - break; - } + request.header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString()); + request.content(new StringContentProvider(params.toString())); + } + else + { + path += "?"; + path += params.toString(); + request.path(path); } } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index 225078050b0..f01693dbf53 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -254,6 +254,38 @@ public class HttpClientTest extends AbstractHttpClientServerTest Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8")); } + @Test + public void test_PUT_WithParameters() throws Exception + { + final String paramName = "a"; + final String paramValue = "\u20AC"; + start(new AbstractHandler() + { + @Override + public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + String value = request.getParameter(paramName); + if (paramValue.equals(value)) + { + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/plain"); + response.getOutputStream().print(value); + } + } + }); + + URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort() + "/path?" + paramName + "=" + paramValue); + ContentResponse response = client.newRequest(uri) + .method(HttpMethod.PUT) + .timeout(5, TimeUnit.SECONDS) + .send(); + + Assert.assertNotNull(response); + Assert.assertEquals(200, response.getStatus()); + Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8")); + } + @Test public void test_POST_WithParameters_WithContent() throws Exception {