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:
Oleg Kalnichevski 2014-04-08 08:25:34 +00:00
parent 719daae514
commit 7b9408e75f
3 changed files with 13 additions and 3 deletions

View File

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

View File

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

View File

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