Delegate decision about null target host to route planners
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1585663 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
719daae514
commit
7b9408e75f
|
@ -66,7 +66,6 @@ import org.apache.http.params.HttpParamsNames;
|
|||
import org.apache.http.protocol.BasicHttpContext;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.http.util.Args;
|
||||
import org.apache.http.util.Asserts;
|
||||
|
||||
/**
|
||||
* Internal class.
|
||||
|
@ -122,7 +121,6 @@ class InternalHttpClient extends CloseableHttpClient {
|
|||
if (host == null) {
|
||||
host = (HttpHost) request.getParams().getParameter(ClientPNames.DEFAULT_HOST);
|
||||
}
|
||||
Asserts.notNull(host, "Target host");
|
||||
return this.routePlanner.determineRoute(host, request, context);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.InetAddress;
|
|||
import org.apache.http.HttpException;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.annotation.Immutable;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
|
@ -64,8 +65,10 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
|
|||
final HttpHost host,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws HttpException {
|
||||
Args.notNull(host, "Target host");
|
||||
Args.notNull(request, "Request");
|
||||
if (host == null) {
|
||||
throw new ProtocolException("Target host is not specified");
|
||||
}
|
||||
final HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
final RequestConfig config = clientContext.getRequestConfig();
|
||||
final InetAddress local = config.getLocalAddress();
|
||||
|
|
|
@ -30,6 +30,7 @@ package org.apache.http.impl.conn;
|
|||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.protocol.HttpClientContext;
|
||||
import org.apache.http.conn.SchemePortResolver;
|
||||
|
@ -102,4 +103,12 @@ public class TestDefaultRoutePlanner {
|
|||
Mockito.verify(schemePortResolver, Mockito.never()).resolve(Mockito.<HttpHost>any());
|
||||
}
|
||||
|
||||
@Test(expected= ProtocolException.class)
|
||||
public void testNullTarget() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
|
||||
final HttpContext context = new BasicHttpContext();
|
||||
routePlanner.determineRoute(null, request, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue