Skip to content

Commit

Permalink
the unix domain socket test success
Browse files Browse the repository at this point in the history
  • Loading branch information
silence-coding committed Jan 6, 2020
1 parent 9d4135f commit 56da156
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 30 deletions.
1 change: 0 additions & 1 deletion client/src/main/java/org/asynchttpclient/AsyncHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/org/asynchttpclient/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
11 changes: 6 additions & 5 deletions client/src/main/java/org/asynchttpclient/RequestBuilderBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
import io.netty.handler.codec.http.HttpResponse;
import org.asynchttpclient.Request;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.slf4j.LoggerFactory;

import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -240,7 +241,7 @@ private <T> ListenableFuture<T> sendRequestWithOpenChannel(NettyResponseFuture<T
SocketAddress channelRemoteAddress = channel.remoteAddress();
if (channelRemoteAddress != null) {
// otherwise, bad luck, the channel was closed, see bellow
scheduleRequestTimeout(future, (InetSocketAddress) channelRemoteAddress);
scheduleRequestTimeout(future, channelRemoteAddress);
}

future.setChannelState(ChannelState.POOLED);
Expand Down Expand Up @@ -400,12 +401,15 @@ private <T> Future<List<DomainSocketAddress>> 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<List<DomainSocketAddress>> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 56da156

Please sign in to comment.