-
Notifications
You must be signed in to change notification settings - Fork 1.6k
SOCKS proxy support #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOCKS proxy support #1466
Conversation
It seems that tests are failing because gatling.io is returning 301 Moved Permanently for every request on port 80. Am I right? |
Right, sorry for that (we switched today to https and plain http gets redirected). Thanks a lot! |
9334a56
to
391b4d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lesiuk Sorry for the very long delay. Could you please have a look at my comments? Thanks!
if (request.getUri().isWebSocket() && proxy == null) { | ||
promise.setSuccess(wsBootstrap); | ||
} else { | ||
if (proxy != null && proxy.getProxyType().isSocks()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please collapse into else if
promise.setSuccess(wsBootstrap); | ||
} else { | ||
if (proxy != null && proxy.getProxyType().isSocks()) { | ||
request.getNameResolver().resolve(proxy.getHost()).addListener((Future<InetAddress> proxyDnsFuture) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/proxyDnsFuture/whenProxyAddress
@Override | ||
protected void initChannel(Channel channel) throws Exception { | ||
InetSocketAddress proxyAddress = new InetSocketAddress(proxyDnsFuture.get(), proxy.getPort()); | ||
if (proxy.getProxyType() == ProxyType.SOCKS_V4) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch
instead of if/else
@@ -108,7 +97,8 @@ public NettyRequestSender(AsyncHttpClientConfig config,// | |||
ProxyServer proxyServer = getProxyServer(config, request); | |||
|
|||
// websockets use connect tunnelling to work with proxies | |||
if (proxyServer != null && (request.getUri().isSecured() || request.getUri().isWebSocket()) && !isConnectDone(request, future)) | |||
if (proxyServer != null && (request.getUri().isSecured() || request.getUri().isWebSocket()) && !isConnectDone(request, future) // | |||
&& !proxyServer.getProxyType().isSocks()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, should be proxyServer.getProxyType() == ProxyType.HTTP
connectionSemaphore.releaseChannelLock(partitionKeyLock); | ||
} | ||
}); | ||
channel.closeFuture().addListener(future -> connectionSemaphore.releaseChannelLock(partitionKeyLock)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but not related to this feature. Please revert (I'll push it right away).
@@ -332,7 +326,7 @@ protected void onFailure(Throwable cause) { | |||
Uri uri = request.getUri(); | |||
final Promise<List<InetSocketAddress>> promise = ImmediateEventExecutor.INSTANCE.newPromise(); | |||
|
|||
if (proxy != null && !proxy.isIgnoredForHost(uri.getHost())) { | |||
if (proxy != null && !proxy.isIgnoredForHost(uri.getHost()) && !proxy.getProxyType().isSocks()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency, should be proxyServer.getProxyType() == ProxyType.HTTP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, is this really needed? The point here is to honor proxy's ignoredHosts, doesn't seem related to proxy type.
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
public class SOCKSProxy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix case to SocksProxy
@@ -332,7 +326,7 @@ protected void onFailure(Throwable cause) { | |||
Uri uri = request.getUri(); | |||
final Promise<List<InetSocketAddress>> promise = ImmediateEventExecutor.INSTANCE.newPromise(); | |||
|
|||
if (proxy != null && !proxy.isIgnoredForHost(uri.getHost())) { | |||
if (proxy != null && !proxy.isIgnoredForHost(uri.getHost()) && !proxy.getProxyType().isSocks()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, is this really needed? The point here is to honor proxy's ignoredHosts, doesn't seem related to proxy type.
@@ -220,7 +220,7 @@ public String toString() { | |||
sb.append("\t\t").append(header.getKey()).append(": ").append(header.getValue()).append("\n"); | |||
} | |||
sb.append("\tbody=\n").append(getResponseBody()).append("\n")// | |||
.append("}").toString(); | |||
.append("}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Not related to this change though. Will commit separately.
@Lesiuk I've picked your changes with a few nits. Thanks a lot! |
Please provide feedback what you dont like or what would you change. As far as I was testing it works correctly but I'm not sure about my code style so I'm open for suggestions.