405044 - Query parameters lost for non GET or POST.
This commit is contained in:
parent
01c2322615
commit
120b8c9839
|
@ -191,25 +191,17 @@ public class HttpConnection extends AbstractConnection implements Connection
|
||||||
params.append("&");
|
params.append("&");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Behave as a GET, adding the params to the path, if it's a POST with some content
|
// POST with no content, send parameters as body
|
||||||
if (method == HttpMethod.POST && request.getContent() != null)
|
if (method == HttpMethod.POST && request.getContent() == null)
|
||||||
method = HttpMethod.GET;
|
|
||||||
|
|
||||||
switch (method)
|
|
||||||
{
|
{
|
||||||
case GET:
|
request.header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString());
|
||||||
|
request.content(new StringContentProvider(params.toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
path += "?";
|
path += "?";
|
||||||
path += params.toString();
|
path += params.toString();
|
||||||
request.path(path);
|
request.path(path);
|
||||||
break;
|
|
||||||
}
|
|
||||||
case POST:
|
|
||||||
{
|
|
||||||
request.header(HttpHeader.CONTENT_TYPE, MimeTypes.Type.FORM_ENCODED.asString());
|
|
||||||
request.content(new StringContentProvider(params.toString()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,38 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
||||||
Assert.assertEquals(paramValue, new String(response.getContent(), "UTF-8"));
|
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
|
@Test
|
||||||
public void test_POST_WithParameters_WithContent() throws Exception
|
public void test_POST_WithParameters_WithContent() throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue