Skip to content

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

Closed
wants to merge 2 commits into from
Closed

SOCKS proxy support #1466

wants to merge 2 commits into from

Conversation

Lesiuk
Copy link

@Lesiuk Lesiuk commented Oct 2, 2017

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.

@Lesiuk
Copy link
Author

Lesiuk commented Oct 2, 2017

It seems that tests are failing because gatling.io is returning 301 Moved Permanently for every request on port 80. Am I right?

@slandelle
Copy link
Contributor

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).
Please let me fix the test suite. Could you please then rebase?
I'm pretty swamped atm, so I'm afraid I'll only be able to review next week. Is that OK for you?

Thanks a lot!

@Lesiuk Lesiuk changed the title Implemented SOCKS proxy support SOCKS proxy support Oct 3, 2017
@slandelle slandelle force-pushed the master branch 5 times, most recently from 9334a56 to 391b4d8 Compare November 28, 2017 12:10
Copy link
Contributor

@slandelle slandelle left a 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()) {
Copy link
Contributor

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) -> {
Copy link
Contributor

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) {
Copy link
Contributor

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())
Copy link
Contributor

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));
Copy link
Contributor

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()) {
Copy link
Contributor

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

Copy link
Contributor

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 {
Copy link
Contributor

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

@slandelle slandelle added this to the 2.1.0 milestone Jan 11, 2018
@@ -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()) {
Copy link
Contributor

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("}");
Copy link
Contributor

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.

@slandelle slandelle closed this in a989753 Jan 12, 2018
@slandelle
Copy link
Contributor

@Lesiuk I've picked your changes with a few nits. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants