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:
parent
937c3b13b8
commit
2ff8962f9f
|
@ -88,7 +88,7 @@ public class HttpRequest implements Request
|
||||||
path = uri.getRawPath();
|
path = uri.getRawPath();
|
||||||
query = uri.getRawQuery();
|
query = uri.getRawQuery();
|
||||||
extractParams(query);
|
extractParams(query);
|
||||||
this.uri = buildURI();
|
this.uri = buildURI(true);
|
||||||
followRedirects(client.isFollowRedirects());
|
followRedirects(client.isFollowRedirects());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public class HttpRequest implements Request
|
||||||
public Request scheme(String scheme)
|
public Request scheme(String scheme)
|
||||||
{
|
{
|
||||||
this.scheme = scheme;
|
this.scheme = scheme;
|
||||||
this.uri = buildURI();
|
this.uri = buildURI(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,9 @@ public class HttpRequest implements Request
|
||||||
params.clear();
|
params.clear();
|
||||||
extractParams(query);
|
extractParams(query);
|
||||||
}
|
}
|
||||||
this.uri = buildURI();
|
this.uri = buildURI(true);
|
||||||
|
if (uri.isAbsolute())
|
||||||
|
this.path = buildURI(false).toString();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,11 +554,11 @@ public class HttpRequest implements Request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private URI buildURI()
|
private URI buildURI(boolean withQuery)
|
||||||
{
|
{
|
||||||
String path = getPath();
|
String path = getPath();
|
||||||
String query = getQuery();
|
String query = getQuery();
|
||||||
if (query != null)
|
if (query != null && withQuery)
|
||||||
path += "?" + query;
|
path += "?" + query;
|
||||||
URI result = URI.create(path);
|
URI result = URI.create(path);
|
||||||
if (!result.isAbsolute())
|
if (!result.isAbsolute())
|
||||||
|
|
|
@ -96,8 +96,8 @@ public interface Request
|
||||||
* Specifies the path - and possibly the query - of this request.
|
* Specifies the path - and possibly the query - of this request.
|
||||||
* If the query part is specified, parameter values must be properly
|
* If the query part is specified, parameter values must be properly
|
||||||
* {@link URLEncoder#encode(String, String) UTF-8 URL encoded}.
|
* {@link URLEncoder#encode(String, String) UTF-8 URL encoded}.
|
||||||
* For example, if the parameter value is the euro symbol € then the
|
* For example, if the value for parameter "currency" is the euro symbol € then the
|
||||||
* query string must be "param=%E2%82%AC".
|
* query string for this parameter must be "currency=%E2%82%AC".
|
||||||
* For transparent encoding of parameter values, use {@link #param(String, String)}.
|
* For transparent encoding of parameter values, use {@link #param(String, String)}.
|
||||||
*
|
*
|
||||||
* @param path the path of this request, such as "/" or "/path?param=1"
|
* @param path the path of this request, such as "/" or "/path?param=1"
|
||||||
|
|
|
@ -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
|
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
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);
|
response.setStatus(status);
|
||||||
|
else
|
||||||
|
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue