|
24 | 24 | import org.asynchttpclient.Dsl; |
25 | 25 | import org.asynchttpclient.Realm; |
26 | 26 | import org.asynchttpclient.config.AsyncHttpClientConfigDefaults; |
| 27 | +import org.asynchttpclient.proxy.ProxyServer; |
27 | 28 | import org.openqa.selenium.Credentials; |
28 | 29 | import org.openqa.selenium.UsernameAndPassword; |
29 | 30 | import org.openqa.selenium.internal.Require; |
|
40 | 41 | import io.netty.util.Timer; |
41 | 42 | import io.netty.util.concurrent.DefaultThreadFactory; |
42 | 43 |
|
| 44 | +import java.net.InetSocketAddress; |
43 | 45 | import java.util.concurrent.ThreadFactory; |
44 | 46 | import java.util.concurrent.TimeUnit; |
45 | 47 | import java.util.function.BiFunction; |
@@ -88,18 +90,30 @@ private static AsyncHttpClient createHttpClient(ClientConfig config) { |
88 | 90 | .setRequestTimeout(toClampedInt(config.readTimeout().toMillis())) |
89 | 91 | .setConnectTimeout(toClampedInt(config.connectionTimeout().toMillis())) |
90 | 92 | .setReadTimeout(toClampedInt(config.readTimeout().toMillis())) |
91 | | - .setUseProxyProperties(true) |
92 | | - .setUseProxySelector(true) |
93 | 93 | .setFollowRedirect(true); |
94 | 94 |
|
| 95 | + Realm.Builder realmBuilder = null; |
95 | 96 | if (config.credentials() != null) { |
96 | 97 | Credentials credentials = config.credentials(); |
97 | 98 | if (!(credentials instanceof UsernameAndPassword)) { |
98 | 99 | throw new IllegalArgumentException("Credentials must be a username and password"); |
99 | 100 | } |
100 | 101 | UsernameAndPassword uap = (UsernameAndPassword) credentials; |
101 | | - builder.setRealm( |
102 | | - new Realm.Builder(uap.username(), uap.password()).setUsePreemptiveAuth(true)); |
| 102 | + realmBuilder = new Realm.Builder(uap.username(), uap.password()); |
| 103 | + builder.setRealm(realmBuilder.setUsePreemptiveAuth(true)); |
| 104 | + } |
| 105 | + |
| 106 | + if (config.proxy() != null) { |
| 107 | + InetSocketAddress address = (InetSocketAddress) config.proxy().address(); |
| 108 | + ProxyServer.Builder proxyBuilder = new ProxyServer.Builder( |
| 109 | + address.getHostName(), address.getPort()); |
| 110 | + if (realmBuilder != null) { |
| 111 | + proxyBuilder.setRealm(realmBuilder); |
| 112 | + } |
| 113 | + builder.setProxyServer(proxyBuilder); |
| 114 | + } else { |
| 115 | + builder.setUseProxyProperties(true) |
| 116 | + .setUseProxySelector(true); |
103 | 117 | } |
104 | 118 |
|
105 | 119 | return Dsl.asyncHttpClient(builder); |
|
0 commit comments