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 458dca3d92d..b44caddbb4a 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 @@ -88,7 +88,7 @@ public class HttpRequest implements Request path = uri.getRawPath(); query = uri.getRawQuery(); extractParams(query); - this.uri = buildURI(); + this.uri = buildURI(true); followRedirects(client.isFollowRedirects()); } @@ -108,7 +108,7 @@ public class HttpRequest implements Request public Request scheme(String scheme) { this.scheme = scheme; - this.uri = buildURI(); + this.uri = buildURI(true); return this; } @@ -155,7 +155,9 @@ public class HttpRequest implements Request params.clear(); extractParams(query); } - this.uri = buildURI(); + this.uri = buildURI(true); + if (uri.isAbsolute()) + this.path = buildURI(false).toString(); return this; } @@ -552,11 +554,11 @@ public class HttpRequest implements Request } } - private URI buildURI() + private URI buildURI(boolean withQuery) { String path = getPath(); String query = getQuery(); - if (query != null) + if (query != null && withQuery) path += "?" + query; URI result = URI.create(path); if (!result.isAbsolute()) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java index 252aff12822..d582028272f 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java @@ -96,8 +96,8 @@ public interface Request * Specifies the path - and possibly the query - of this request. * If the query part is specified, parameter values must be properly * {@link URLEncoder#encode(String, String) UTF-8 URL encoded}. - * For example, if the parameter value is the euro symbol € then the - * query string must be "param=%E2%82%AC". + * For example, if the value for parameter "currency" is the euro symbol € then the + * query string for this parameter must be "currency=%E2%82%AC". * For transparent encoding of parameter values, use {@link #param(String, String)}. * * @param path the path of this request, such as "/" or "/path?param=1" diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java index c645f1cdb3e..1c35264ea57 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientProxyTest.java @@ -57,8 +57,12 @@ public class HttpClientProxyTest extends AbstractHttpClientServerTest public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); - if (serverHost.equals(request.getServerName())) + if (!URI.create(baseRequest.getUri().toString()).isAbsolute()) + response.setStatus(HttpServletResponse.SC_USE_PROXY); + else if (serverHost.equals(request.getServerName())) response.setStatus(status); + else + response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE); } });