Skip to content

Commit

Permalink
get host from authority if uri.getHost null
Browse files Browse the repository at this point in the history
uri sometimes fails to parse host (when starts with _, etc,
but correctly parses authority.)
  • Loading branch information
jloomis committed Jun 20, 2011
1 parent d6ee389 commit 7dc0ce0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,8 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
HttpMethod m,
URI uri,
ChannelBuffer buffer) throws IOException {
String host = uri.getHost();

String host = AsyncHttpProviderUtils.getHost(uri);

if (request.getVirtualHost() != null) {
host = request.getVirtualHost();
Expand Down Expand Up @@ -899,7 +900,7 @@ private <T> ListenableFuture<T> doConnect(final Request request, final AsyncHand

try {
if (proxyServer == null || avoidProxy) {
channelFuture = bootstrap.connect(new InetSocketAddress(uri.getHost(), AsyncHttpProviderUtils.getPort(uri)));
channelFuture = bootstrap.connect(new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)));
} else {
channelFuture = bootstrap.connect(new InetSocketAddress(proxyServer.getHost(), proxyServer.getPort()));
}
Expand Down Expand Up @@ -1301,7 +1302,7 @@ private Realm kerberosChallenge(List<String> proxyAuth,
NettyResponseFuture<?> future) throws NTLMEngineException {

URI uri = URI.create(request.getUrl());
String host = request.getVirtualHost() == null ? uri.getHost() : request.getVirtualHost();
String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost();
String server = proxyServer == null ? host : proxyServer.getHost();
try {
String challengeHeader = spnegoEngine.generateToken(server);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ public final static byte[] contentToByte(Collection<HttpResponseBodyPart> bodyPa
}
}

public final static String getHost(URI uri) {
String host = uri.getHost();
if (host == null) {
host = uri.getAuthority();
}
return host;
}

public final static URI getRedirectUri(URI uri, String location) {
URI newUri = uri.resolve(location);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ning/http/util/ProxyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ProxyUtils {
* @return true if we have to avoid proxy use (obeying non-proxy hosts settings), false otherwise.
*/
public static boolean avoidProxy(final ProxyServer proxyServer, final Request request) {
return avoidProxy(proxyServer, URI.create(request.getUrl()).getHost());
return avoidProxy(proxyServer, AsyncHttpProviderUtils.getHost(URI.create(request.getUrl())));
}

/**
Expand Down

0 comments on commit 7dc0ce0

Please sign in to comment.