Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2013-04-05 17:20:04 -0400
committerSimone Bordet2013-04-05 17:20:19 -0400
commit120b8c98396f8176bf80798ed86db5a6568381c8 (patch)
tree339103e7e8d5e6ddbb499db163cca8a0795dcf9f
parent01c23226157a9aa01bf68c66575dea8f9e2f2d8c (diff)
downloadorg.eclipse.jetty.project-120b8c98396f8176bf80798ed86db5a6568381c8.tar.gz
org.eclipse.jetty.project-120b8c98396f8176bf80798ed86db5a6568381c8.tar.xz
org.eclipse.jetty.project-120b8c98396f8176bf80798ed86db5a6568381c8.zip
405044 - Query parameters lost for non GET or POST.
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java28
-rw-r--r--jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java32
2 files changed, 42 insertions, 18 deletions
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 ad96efbad7..ca61d22413 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 225078050b..f01693dbf5 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
@@ -255,6 +255,38 @@ public class HttpClientTest extends AbstractHttpClientServerTest
}
@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
{
final byte[] content = {0, 1, 2, 3};

Back to the top