410083 - Jetty clients submits incomplete URL to proxy.

Made the request URI absolute in case the HttpClient is configured with a forward proxy.
This commit is contained in:
Simone Bordet 2013-06-07 16:34:10 +02:00
parent 937c3b13b8
commit 2ff8962f9f
3 changed files with 14 additions and 8 deletions

View File

@ -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())

View File

@ -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"

View File

@ -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);
}
});