@@ -174,17 +174,34 @@ public NettyAsyncHttpClientBuilder(HttpClient nettyHttpClient) {
174
174
public com .azure .core .http .HttpClient build () {
175
175
HttpClient nettyHttpClient ;
176
176
177
+ Configuration buildConfiguration
178
+ = (configuration == null ) ? Configuration .getGlobalConfiguration () : configuration ;
179
+
180
+ ProxyOptions buildProxyOptions
181
+ = proxyOptions == null ? ProxyOptions .fromConfiguration (buildConfiguration , true ) : proxyOptions ;
182
+
183
+ /*
184
+ * Only configure the custom authorization challenge handler and challenge holder when using an authenticated
185
+ * HTTP proxy. All other proxying such as SOCKS4, SOCKS5, and anonymous HTTP will use Netty's built-in handlers.
186
+ */
187
+ boolean useCustomProxyHandler = shouldUseCustomProxyHandler (buildProxyOptions );
188
+ AuthorizationChallengeHandler handler = useCustomProxyHandler
189
+ ? new AuthorizationChallengeHandler (buildProxyOptions .getUsername (), buildProxyOptions .getPassword ())
190
+ : null ;
191
+ AtomicReference <ChallengeHolder > proxyChallengeHolder = useCustomProxyHandler ? new AtomicReference <>() : null ;
192
+
177
193
// Used to track if the builder set the DefaultAddressResolverGroup. If it did, when proxying it allows the
178
194
// no-op address resolver to be set.
179
- boolean addressResolverWasSetByBuilder = false ;
180
195
if (this .baseHttpClient != null ) {
181
196
nettyHttpClient = baseHttpClient ;
182
197
} else if (this .connectionProvider != null ) {
183
- nettyHttpClient = HttpClient .create (this .connectionProvider ).resolver (DefaultAddressResolverGroup .INSTANCE );
184
- addressResolverWasSetByBuilder = true ;
198
+ nettyHttpClient = HttpClient .create (this .connectionProvider );
185
199
} else {
186
- nettyHttpClient = HttpClient .create ().resolver (DefaultAddressResolverGroup .INSTANCE );
187
- addressResolverWasSetByBuilder = true ;
200
+ nettyHttpClient = HttpClient .create ();
201
+ }
202
+
203
+ if (proxyOptions == null ) {
204
+ nettyHttpClient = nettyHttpClient .resolver (DefaultAddressResolverGroup .INSTANCE );
188
205
}
189
206
190
207
long writeTimeout = getTimeout (this .writeTimeout , getDefaultWriteTimeout ()).toMillis ();
@@ -213,22 +230,6 @@ public com.azure.core.http.HttpClient build() {
213
230
nettyHttpClient .wiretap (enableWiretap );
214
231
}
215
232
216
- Configuration buildConfiguration
217
- = (configuration == null ) ? Configuration .getGlobalConfiguration () : configuration ;
218
-
219
- ProxyOptions buildProxyOptions
220
- = proxyOptions == null ? ProxyOptions .fromConfiguration (buildConfiguration , true ) : proxyOptions ;
221
-
222
- /*
223
- * Only configure the custom authorization challenge handler and challenge holder when using an authenticated
224
- * HTTP proxy. All other proxying such as SOCKS4, SOCKS5, and anonymous HTTP will use Netty's built-in handlers.
225
- */
226
- boolean useCustomProxyHandler = shouldUseCustomProxyHandler (buildProxyOptions );
227
- AuthorizationChallengeHandler handler = useCustomProxyHandler
228
- ? new AuthorizationChallengeHandler (buildProxyOptions .getUsername (), buildProxyOptions .getPassword ())
229
- : null ;
230
- AtomicReference <ChallengeHolder > proxyChallengeHolder = useCustomProxyHandler ? new AtomicReference <>() : null ;
231
-
232
233
boolean addProxyHandler = false ;
233
234
234
235
if (eventLoopGroup != null ) {
@@ -257,6 +258,12 @@ public com.azure.core.http.HttpClient build() {
257
258
handler , proxyChallengeHolder ));
258
259
}
259
260
});
261
+
262
+ AddressResolverGroup <?> resolver = nettyHttpClient .configuration ().resolver ();
263
+ if (resolver == null ) {
264
+ // This mimics behaviors seen when Reactor Netty proxying is used.
265
+ nettyHttpClient = nettyHttpClient .resolver (NoopAddressResolverGroup .INSTANCE );
266
+ }
260
267
} else {
261
268
nettyHttpClient
262
269
= nettyHttpClient .proxy (proxy -> proxy .type (toReactorNettyProxyType (buildProxyOptions .getType ()))
@@ -265,12 +272,6 @@ public com.azure.core.http.HttpClient build() {
265
272
.password (ignored -> buildProxyOptions .getPassword ())
266
273
.nonProxyHosts (buildProxyOptions .getNonProxyHosts ()));
267
274
}
268
-
269
- AddressResolverGroup <?> resolver = nettyHttpClient .configuration ().resolver ();
270
- if (resolver == null || addressResolverWasSetByBuilder ) {
271
- // This mimics behaviors seen when Reactor Netty proxying is used.
272
- nettyHttpClient = nettyHttpClient .resolver (NoopAddressResolverGroup .INSTANCE );
273
- }
274
275
}
275
276
276
277
return new NettyAsyncHttpClient (nettyHttpClient , disableBufferCopy , addProxyHandler );
0 commit comments