diff --git a/client/src/main/java/org/asynchttpclient/AsyncHandler.java b/client/src/main/java/org/asynchttpclient/AsyncHandler.java index 8cec31e40d..f17fd9275c 100644 --- a/client/src/main/java/org/asynchttpclient/AsyncHandler.java +++ b/client/src/main/java/org/asynchttpclient/AsyncHandler.java @@ -20,7 +20,6 @@ import org.asynchttpclient.netty.request.NettyRequest; import javax.net.ssl.SSLSession; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; diff --git a/client/src/main/java/org/asynchttpclient/Request.java b/client/src/main/java/org/asynchttpclient/Request.java index d608c8f9c5..10d9c9a0f4 100644 --- a/client/src/main/java/org/asynchttpclient/Request.java +++ b/client/src/main/java/org/asynchttpclient/Request.java @@ -64,7 +64,7 @@ public interface Request { String getUrl(); /** - * @return the InetAddress to be used to bypass uri's hostname resolution + * @return the SocketAddress to be used to bypass uri's hostname or unix domain path resolution */ SocketAddress getAddress(); diff --git a/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java index 95079c5349..06921420ca 100644 --- a/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/client/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -167,16 +167,17 @@ public T setAddress(InetAddress address) { return asDerivedType(); } - public T setLocalAddress(InetAddress address) { - this.localAddress = new InetSocketAddress(address,0); + public T setAddress(SocketAddress address) { + this.address = address; return asDerivedType(); } - public T setDomainAddress(DomainSocketAddress address) { - this.address = address; + + public T setLocalAddress(InetAddress address) { + this.localAddress = new InetSocketAddress(address,0); return asDerivedType(); } - public T setDomainLocalAddress(DomainSocketAddress address) { + public T setLocalAddress(SocketAddress address) { this.localAddress = address; return asDerivedType(); } diff --git a/client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java b/client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java index a1f984c474..e90f0ce76f 100644 --- a/client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java +++ b/client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java @@ -5,7 +5,6 @@ import io.netty.handler.codec.http.HttpUtil; import org.asynchttpclient.Request; -import java.net.InetSocketAddress; import java.net.SocketAddress; import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE; diff --git a/client/src/main/java/org/asynchttpclient/channel/KeepAliveStrategy.java b/client/src/main/java/org/asynchttpclient/channel/KeepAliveStrategy.java index 3da3f4c611..002a8aaef7 100644 --- a/client/src/main/java/org/asynchttpclient/channel/KeepAliveStrategy.java +++ b/client/src/main/java/org/asynchttpclient/channel/KeepAliveStrategy.java @@ -17,7 +17,6 @@ import io.netty.handler.codec.http.HttpResponse; import org.asynchttpclient.Request; -import java.net.InetSocketAddress; import java.net.SocketAddress; public interface KeepAliveStrategy { @@ -25,7 +24,7 @@ public interface KeepAliveStrategy { /** * Determines whether the connection should be kept alive after this HTTP message exchange. * - * @param remoteAddress the remote InetSocketAddress associated with the request + * @param remoteAddress the remote SocketAddress associated with the request * @param ahcRequest the Request, as built by AHC * @param nettyRequest the HTTP request sent to Netty * @param nettyResponse the HTTP response received from Netty diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/NettyChannelConnector.java b/client/src/main/java/org/asynchttpclient/netty/channel/NettyChannelConnector.java index 04b36d7fc9..92a5b31012 100644 --- a/client/src/main/java/org/asynchttpclient/netty/channel/NettyChannelConnector.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/NettyChannelConnector.java @@ -20,8 +20,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; import java.util.concurrent.RejectedExecutionException; diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java b/client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java index a01e5fbcca..997b1c1b9b 100755 --- a/client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java @@ -29,7 +29,6 @@ import org.slf4j.LoggerFactory; import java.net.ConnectException; -import java.net.InetSocketAddress; import java.net.SocketAddress; /** diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java b/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java index 2393aca855..db9fb7cc24 100755 --- a/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java @@ -30,7 +30,6 @@ import org.asynchttpclient.netty.request.NettyRequestSender; import java.io.IOException; -import java.net.InetSocketAddress; @Sharable public final class HttpHandler extends AsyncHttpClientHandler { diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java index 56cfd293d8..1253f8722a 100644 --- a/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/intercept/Redirect30xInterceptor.java @@ -32,9 +32,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -93,11 +90,10 @@ public boolean exitAfterHandlingRedirect(Channel channel, && (statusCode == MOVED_PERMANENTLY_301 || statusCode == SEE_OTHER_303 || (statusCode == FOUND_302 && !config.isStrict302Handling())); boolean keepBody = statusCode == TEMPORARY_REDIRECT_307 || statusCode == PERMANENT_REDIRECT_308 || (statusCode == FOUND_302 && config.isStrict302Handling()); - InetSocketAddress localAddress = (InetSocketAddress) request.getLocalAddress(); final RequestBuilder requestBuilder = new RequestBuilder(switchToGet ? GET : originalMethod) .setChannelPoolPartitioning(request.getChannelPoolPartitioning()) .setFollowRedirect(true) - .setLocalAddress(localAddress.getAddress()) + .setLocalAddress(request.getLocalAddress()) .setNameResolver(request.getNameResolver()) .setDomainNameResolver(request.getDomainNameResolver()) .setProxyServer(request.getProxyServer()) diff --git a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java index 20c5a0acdb..f7cb2fcaaf 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.Arrays; import java.util.List; import static io.netty.handler.codec.http.HttpHeaderNames.EXPECT; @@ -240,7 +241,7 @@ private ListenableFuture sendRequestWithOpenChannel(NettyResponseFuture Future> resolveDomainAddresses(Request req if (proxy != null ) { throw new IllegalArgumentException("Unix domain socket not support proxy"); } else { - DomainSocketAddress socketAddress = new DomainSocketAddress(config.getUnixSocket()); scheduleRequestTimeout(future, socketAddress); - - if (request.getAddress() != null) { - throw new IllegalArgumentException("Unix domain socket not support set address !"); + SocketAddress address = request.getAddress(); + if (address != null) { + final Promise> promise = ImmediateEventExecutor.INSTANCE.newPromise(); + if (!(address instanceof DomainSocketAddress)){ + throw new IllegalArgumentException("address must be instance of DomainSocketAddress"); + } + return promise.setSuccess(singletonList((DomainSocketAddress) address)); } else { return RequestHostnameResolver.INSTANCE.resolve(request.getDomainNameResolver(), socketAddress, asyncHandler); } diff --git a/client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java b/client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java index 2d41bf57c9..06c2607450 100755 --- a/client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java +++ b/client/src/main/java/org/asynchttpclient/netty/timeout/TimeoutsHolder.java @@ -21,7 +21,6 @@ import org.asynchttpclient.netty.NettyResponseFuture; import org.asynchttpclient.netty.request.NettyRequestSender; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java b/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java index a3bb6145ea..9a88ae513d 100644 --- a/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java +++ b/client/src/test/java/org/asynchttpclient/test/EventCollectingHandler.java @@ -21,7 +21,6 @@ import org.testng.Assert; import javax.net.ssl.SSLSession; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.List; import java.util.Queue; diff --git a/example/src/main/java/org/asynchttpclient/example/completable/CompletableFutures.java b/example/src/main/java/org/asynchttpclient/example/completable/CompletableFutures.java index bbb5df2917..f36878143a 100644 --- a/example/src/main/java/org/asynchttpclient/example/completable/CompletableFutures.java +++ b/example/src/main/java/org/asynchttpclient/example/completable/CompletableFutures.java @@ -48,9 +48,6 @@ public static void main(String[] args) throws IOException { .thenApply(Response::getResponseBody) .thenAccept(System.out::println) .join(); - } - // support unix domain socket - try (AsyncHttpClient asyncHttpClient = asyncHttpClient(config)) { asyncHttpClient .prepareGet("/hello/unix") // will add http:127.0.0.1:80 .execute() diff --git a/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java b/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java index c174a6ebbb..528e1f4123 100644 --- a/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java +++ b/extras/rxjava2/src/main/java/org/asynchttpclient/extras/rxjava2/maybe/AbstractMaybeAsyncHandlerBridge.java @@ -27,7 +27,6 @@ import org.slf4j.LoggerFactory; import javax.net.ssl.SSLSession; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Arrays; import java.util.List;