457130 - HTTPS request with IP host and HTTP proxy throws IllegalArgumentException.
Fixed by handling the case of non-URI request target.
This commit is contained in:
parent
3456c78d54
commit
adae3193d8
|
@ -134,10 +134,14 @@ public abstract class HttpConnection implements Connection
|
|||
CookieStore cookieStore = getHttpClient().getCookieStore();
|
||||
if (cookieStore != null)
|
||||
{
|
||||
StringBuilder cookies = convertCookies(cookieStore.get(request.getURI()), null);
|
||||
cookies = convertCookies(request.getCookies(), cookies);
|
||||
if (cookies != null)
|
||||
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
|
||||
URI uri = request.getURI();
|
||||
if (uri != null)
|
||||
{
|
||||
StringBuilder cookies = convertCookies(cookieStore.get(uri), null);
|
||||
cookies = convertCookies(request.getCookies(), cookies);
|
||||
if (cookies != null)
|
||||
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Authorization
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpCookie;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -57,6 +58,8 @@ import org.eclipse.jetty.util.Fields;
|
|||
|
||||
public class HttpRequest implements Request
|
||||
{
|
||||
private static final URI NULL_URI = URI.create("null:0");
|
||||
|
||||
private final HttpFields headers = new HttpFields();
|
||||
private final Fields params = new Fields(true);
|
||||
private final List<Response.ResponseListener> responseListeners = new ArrayList<>();
|
||||
|
@ -158,22 +161,30 @@ public class HttpRequest implements Request
|
|||
@Override
|
||||
public Request path(String path)
|
||||
{
|
||||
URI uri = URI.create(path);
|
||||
String rawPath = uri.getRawPath();
|
||||
if (uri.isOpaque())
|
||||
rawPath = path;
|
||||
if (rawPath == null)
|
||||
rawPath = "";
|
||||
this.path = rawPath;
|
||||
String query = uri.getRawQuery();
|
||||
if (query != null)
|
||||
URI uri = newURI(path);
|
||||
if (uri == null)
|
||||
{
|
||||
this.query = query;
|
||||
params.clear();
|
||||
extractParams(query);
|
||||
this.path = path;
|
||||
this.query = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
String rawPath = uri.getRawPath();
|
||||
if (uri.isOpaque())
|
||||
rawPath = path;
|
||||
if (rawPath == null)
|
||||
rawPath = "";
|
||||
this.path = rawPath;
|
||||
String query = uri.getRawQuery();
|
||||
if (query != null)
|
||||
{
|
||||
this.query = query;
|
||||
params.clear();
|
||||
extractParams(query);
|
||||
}
|
||||
if (uri.isAbsolute())
|
||||
this.path = buildURI(false).toString();
|
||||
}
|
||||
if (uri.isAbsolute())
|
||||
this.path = buildURI(false).toString();
|
||||
this.uri = null;
|
||||
return this;
|
||||
}
|
||||
|
@ -187,9 +198,9 @@ public class HttpRequest implements Request
|
|||
@Override
|
||||
public URI getURI()
|
||||
{
|
||||
if (uri != null)
|
||||
return uri;
|
||||
return uri = buildURI(true);
|
||||
if (uri == null)
|
||||
uri = buildURI(true);
|
||||
return uri == NULL_URI ? null : uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -762,12 +773,28 @@ public class HttpRequest implements Request
|
|||
String query = getQuery();
|
||||
if (query != null && withQuery)
|
||||
path += "?" + query;
|
||||
URI result = URI.create(path);
|
||||
URI result = newURI(path);
|
||||
if (result == null)
|
||||
return NULL_URI;
|
||||
if (!result.isAbsolute() && !result.isOpaque())
|
||||
result = URI.create(new Origin(getScheme(), getHost(), getPort()).asString() + path);
|
||||
return result;
|
||||
}
|
||||
|
||||
private URI newURI(String uri)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new URI(uri);
|
||||
}
|
||||
catch (URISyntaxException x)
|
||||
{
|
||||
// The "path" of a HTTP request may not be a URI,
|
||||
// for example for CONNECT 127.0.0.1:8080 or OPTIONS *.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.proxy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.Socket;
|
||||
|
@ -28,7 +26,6 @@ import java.util.concurrent.CountDownLatch;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -64,6 +61,8 @@ import org.junit.Ignore;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ProxyTunnellingTest
|
||||
{
|
||||
@Rule
|
||||
|
@ -148,8 +147,10 @@ public class ProxyTunnellingTest
|
|||
|
||||
try
|
||||
{
|
||||
// Use a numeric host to test the URI of the CONNECT request.
|
||||
String host = "127.0.0.1";
|
||||
String body = "BODY";
|
||||
ContentResponse response = httpClient.newRequest("localhost", serverConnector.getLocalPort())
|
||||
ContentResponse response = httpClient.newRequest(host, serverConnector.getLocalPort())
|
||||
.scheme(HttpScheme.HTTPS.asString())
|
||||
.method(HttpMethod.GET)
|
||||
.path("/echo?body=" + URLEncoder.encode(body, "UTF-8"))
|
||||
|
|
Loading…
Reference in New Issue