Skip to content

Commit

Permalink
Async的proxy模式暂时无法实现
Browse files Browse the repository at this point in the history
  • Loading branch information
dbstarll committed Mar 20, 2023
1 parent 34f1bef commit 8b78b3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ private AsyncClientConnectionManager buildConnectionManagerAsync() {
if (sslContext != null) {
builder.setTlsStrategy(ClientTlsStrategyBuilder.create().setSslContext(sslContext).build());
}
// Async的proxy模式暂时无法实现
// if (proxy != null && proxy.type() == Type.SOCKS && resolveFromProxy) {
// builder.setDnsResolver(new FakeDnsResolver());
// }
if (proxy != null && proxy.type() == Type.SOCKS && resolveFromProxy) {
builder.setDnsResolver(new FakeDnsResolver());
}
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.junit.jupiter.api.function.ThrowingConsumer;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import java.io.IOException;
import java.math.BigInteger;
import java.net.Authenticator;
Expand Down Expand Up @@ -256,17 +257,21 @@ void proxy() throws Throwable {
}
}

// @Test
// void proxyAsync() throws Throwable {
// try (CloseableHttpAsyncClient client = new HttpClientFactory().setSocketTimeout(5000).setConnectTimeout(5000)
// .setProxy(HttpClientFactory.proxy(Type.SOCKS, PROXY_HOST, PROXY_PORT))
// .buildAsync()) {
// client.start();
// final SimpleHttpRequest request = SimpleRequestBuilder.get("https://static.y1cloud.com/ping.html").build();
// final Future<SimpleHttpResponse> future = client.execute(request, null);
@Test
void proxyAsync() throws Throwable {
try (CloseableHttpAsyncClient client = new HttpClientFactory().setSocketTimeout(5000).setConnectTimeout(5000)
.setProxy(HttpClientFactory.proxy(Type.SOCKS, PROXY_HOST, PROXY_PORT))
.buildAsync()) {
client.start();
final SimpleHttpRequest request = SimpleRequestBuilder.get("https://static.y1cloud.com/ping.html").build();
final Future<SimpleHttpResponse> future = client.execute(request, null);
// assertEquals("ok\n", future.get().getBodyText());
// }
// }
// Async模式下的proxy还有问题
final ExecutionException e = assertThrowsExactly(ExecutionException.class, future::get);
assertNotNull(e.getCause());
assertSame(SSLHandshakeException.class, e.getCause().getClass());
}
}

@Test
void proxyWithContext() throws Throwable {
Expand Down

0 comments on commit 8b78b3f

Please sign in to comment.