@@ -62,7 +62,7 @@ use crate::{
62
62
client:: { HttpClient , connect:: TcpConnectOptions , options:: TransportOptions } ,
63
63
rt:: { TokioExecutor , tokio:: TokioTimer } ,
64
64
} ,
65
- dns:: { DnsResolverWithOverrides , DynResolver , GaiResolver , Resolve } ,
65
+ dns:: { DnsResolverWithOverrides , DynResolver , GaiResolver , IntoResolve , Resolve } ,
66
66
error:: { self , BoxError , Error } ,
67
67
header:: OrigHeaderMap ,
68
68
http1:: Http1Options ,
@@ -250,10 +250,9 @@ impl ClientBuilder {
250
250
}
251
251
let proxies = Arc :: new ( proxies) ;
252
252
253
- // Into parts for transport options
254
253
let ( tls_options, http1_options, http2_options) = config. transport_options . into_parts ( ) ;
255
254
256
- // Create the TLS connector with the provided options.
255
+ // create the TLS connector with the provided options.
257
256
let connector = {
258
257
let resolver = {
259
258
let mut resolver: Arc < dyn Resolve > = match config. dns_resolver {
@@ -272,7 +271,7 @@ impl ClientBuilder {
272
271
DynResolver :: new ( resolver)
273
272
} ;
274
273
275
- // Apply http connector options
274
+ // configured http connector options
276
275
let http = |http : & mut HttpConnector | {
277
276
http. enforce_http ( false ) ;
278
277
http. set_keepalive ( config. tcp_keepalive ) ;
@@ -289,7 +288,7 @@ impl ClientBuilder {
289
288
http. set_tcp_user_timeout ( config. tcp_user_timeout ) ;
290
289
} ;
291
290
292
- // Apply tls connector options
291
+ // configured tls connector options
293
292
let tls = |tls : TlsConnectorBuilder | {
294
293
let alpn_protocol = match config. http_version_pref {
295
294
HttpVersionPref :: Http1 => Some ( AlpnProtocol :: HTTP1 ) ,
@@ -317,7 +316,7 @@ impl ClientBuilder {
317
316
. build ( config. connector_layers ) ?
318
317
} ;
319
318
320
- // Create client with the configured connector
319
+ // create client with the configured connector
321
320
let client = {
322
321
let http2_only = matches ! ( config. http_version_pref, HttpVersionPref :: Http2 ) ;
323
322
let mut builder = HttpClient :: builder ( TokioExecutor :: new ( ) ) ;
@@ -333,10 +332,9 @@ impl ClientBuilder {
333
332
builder. build ( connector)
334
333
} ;
335
334
336
- // Create the client with the configured service layers
335
+ // create the client with the configured service layers
337
336
let client = {
338
- // Start with the base client service, which handles headers, original headers,
339
- // HTTPS-only, and proxies.
337
+ // configured client service layer
340
338
let service = ClientService :: new (
341
339
client,
342
340
config. headers ,
@@ -345,13 +343,13 @@ impl ClientBuilder {
345
343
proxies,
346
344
) ;
347
345
348
- // Add cookie service layer if cookies are enabled.
346
+ // configured cookie service layer if cookies are enabled.
349
347
#[ cfg( feature = "cookies" ) ]
350
348
let service = ServiceBuilder :: new ( )
351
349
. layer ( CookieServiceLayer :: new ( config. cookie_store ) )
352
350
. service ( service) ;
353
351
354
- // Add response decompression support (gzip, zstd, brotli, deflate) if enabled.
352
+ // configured response decompression support (gzip, zstd, brotli, deflate) if enabled.
355
353
#[ cfg( any(
356
354
feature = "gzip" ,
357
355
feature = "zstd" ,
@@ -362,12 +360,12 @@ impl ClientBuilder {
362
360
. layer ( DecompressionLayer :: new ( config. accept_encoding ) )
363
361
. service ( service) ;
364
362
365
- // Add a timeout layer for the response body.
363
+ // configured timeout layer for the response body.
366
364
let service = ServiceBuilder :: new ( )
367
365
. layer ( ResponseBodyTimeoutLayer :: new ( config. timeout_options ) )
368
366
. service ( service) ;
369
367
370
- // Add redirect following logic with the configured policy.
368
+ // configured redirect following logic with the configured policy.
371
369
let service = {
372
370
let policy = FollowRedirectPolicy :: new ( config. redirect_policy )
373
371
. with_referer ( config. referer )
@@ -378,14 +376,14 @@ impl ClientBuilder {
378
376
. service ( service)
379
377
} ;
380
378
381
- // Add HTTP/2 retry logic.
379
+ // configured HTTP/2 retry logic.
382
380
let service = ServiceBuilder :: new ( )
383
381
. layer ( RetryLayer :: new ( Http2RetryPolicy :: new (
384
382
config. http2_max_retry ,
385
383
) ) )
386
384
. service ( service) ;
387
385
388
- // Add the configured layers to the service.
386
+ // configured layers to the service.
389
387
if config. layers . is_empty ( ) {
390
388
let service = ServiceBuilder :: new ( )
391
389
. layer ( TimeoutLayer :: new ( config. timeout_options ) )
@@ -1262,8 +1260,11 @@ impl ClientBuilder {
1262
1260
/// Overrides for specific names passed to `resolve` and `resolve_to_addrs` will
1263
1261
/// still be applied on top of this resolver.
1264
1262
#[ inline]
1265
- pub fn dns_resolver ( mut self , resolver : Arc < dyn Resolve > ) -> ClientBuilder {
1266
- self . config . dns_resolver = Some ( resolver) ;
1263
+ pub fn dns_resolver < R > ( mut self , resolver : R ) -> ClientBuilder
1264
+ where
1265
+ R : IntoResolve + Send + Sync + ' static ,
1266
+ {
1267
+ self . config . dns_resolver = Some ( resolver. into_resolve ( ) ) ;
1267
1268
self
1268
1269
}
1269
1270
0 commit comments