From c5f52dc57d4ba53c7ec1c4d80c79bd5699848654 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Fri, 12 Feb 2010 12:42:45 +0000 Subject: [PATCH] HTTPCLIENT-911: improved handling of invalid request uris (host name containing an underscore) git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@909384 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/client/AbstractHttpClient.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java index 726357bcc..84978f4b6 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -624,17 +624,21 @@ public abstract class AbstractHttpClient implements HttpClient { return execute(determineTarget(request), request, context); } - private HttpHost determineTarget(HttpUriRequest request) { + private HttpHost determineTarget(HttpUriRequest request) throws ClientProtocolException { // A null target may be acceptable if there is a default target. // Otherwise, the null target is detected in the director. HttpHost target = null; URI requestURI = request.getURI(); if (requestURI.isAbsolute()) { - target = new HttpHost( - requestURI.getHost(), - requestURI.getPort(), - requestURI.getScheme()); + String host = requestURI.getHost(); + int port = requestURI.getPort(); + String scheme = requestURI.getScheme(); + if (host == null) { + throw new ClientProtocolException( + "URI does not specify a valid host name: " + requestURI); + } + target = new HttpHost(host, port, scheme); } return target; }