From 762e4ba4c3e9dd4fc7bade6e4203caf24ad5cd24 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 16 Jul 2013 21:50:22 +0200 Subject: [PATCH] 413113 - Inconsistent Request.getURI() when adding parameters via Request.param(). Fixed by rebuilding the URI when a call to param() is made. --- .../java/org/eclipse/jetty/client/HttpRequest.java | 1 + .../org/eclipse/jetty/client/HttpClientURITest.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java index ca750b7cb8a..741f62b240c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java @@ -196,6 +196,7 @@ public class HttpRequest implements Request { params.add(name, value); this.query = buildQuery(); + this.uri = buildURI(true); return this; } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java index 0727e3af331..7e46e95b5a9 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientURITest.java @@ -108,13 +108,15 @@ public class HttpClientURITest extends AbstractHttpClientServerTest } }); + String pathQuery = path + "?" + query; Request request = client.newRequest("localhost", connector.getLocalPort()) .scheme(scheme) .timeout(5, TimeUnit.SECONDS) - .path(path + "?" + query); + .path(pathQuery); Assert.assertEquals(path, request.getPath()); Assert.assertEquals(query, request.getQuery()); + Assert.assertTrue(request.getURI().toString().endsWith(pathQuery)); Fields params = request.getParams(); Assert.assertEquals(1, params.size()); Assert.assertEquals(value, params.get(name).value()); @@ -131,6 +133,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest String value = "1"; final String query = name + "=" + value; final String path = "/path"; + String pathQuery = path + "?" + query; start(new AbstractHandler() { @Override @@ -150,6 +153,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest Assert.assertEquals(path, request.getPath()); Assert.assertEquals(query, request.getQuery()); + Assert.assertTrue(request.getURI().toString().endsWith(pathQuery)); Fields params = request.getParams(); Assert.assertEquals(1, params.size()); Assert.assertEquals(value, params.get(name).value()); @@ -168,6 +172,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest String value2 = "2"; final String query = name1 + "=" + value1 + "&" + name2 + "=" + value2; final String path = "/path"; + String pathQuery = path + "?" + query; start(new AbstractHandler() { @Override @@ -187,6 +192,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest Assert.assertEquals(path, request.getPath()); Assert.assertEquals(query, request.getQuery()); + Assert.assertTrue(request.getURI().toString().endsWith(pathQuery)); Fields params = request.getParams(); Assert.assertEquals(2, params.size()); Assert.assertEquals(value1, params.get(name1).value()); @@ -208,6 +214,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest String encodedValue2 = URLEncoder.encode(value2, "UTF-8"); final String query = name1 + "=" + encodedValue1 + "&" + name2 + "=" + encodedValue2; final String path = "/path"; + String pathQuery = path + "?" + query; start(new AbstractHandler() { @Override @@ -229,6 +236,7 @@ public class HttpClientURITest extends AbstractHttpClientServerTest Assert.assertEquals(path, request.getPath()); Assert.assertEquals(query, request.getQuery()); + Assert.assertTrue(request.getURI().toString().endsWith(pathQuery)); Fields params = request.getParams(); Assert.assertEquals(2, params.size()); Assert.assertEquals(value1, params.get(name1).value());