50
50
51
51
use std:: fmt;
52
52
use std:: mem;
53
- use std:: sync:: Arc ;
54
53
use std:: time:: Duration ;
55
54
56
55
use futures_channel:: oneshot;
@@ -230,14 +229,13 @@ where
230
229
other => return ResponseFuture :: error_version ( other) ,
231
230
} ;
232
231
233
- let domain = match extract_domain ( req. uri_mut ( ) , is_http_connect) {
232
+ let pool_key = match extract_domain ( req. uri_mut ( ) , is_http_connect) {
234
233
Ok ( s) => s,
235
234
Err ( err) => {
236
235
return ResponseFuture :: new ( Box :: new ( future:: err ( err) ) ) ;
237
236
}
238
237
} ;
239
238
240
- let pool_key = Arc :: new ( domain) ;
241
239
ResponseFuture :: new ( Box :: new ( self . retryably_send_request ( req, pool_key) ) )
242
240
}
243
241
@@ -281,7 +279,7 @@ where
281
279
mut req : Request < B > ,
282
280
pool_key : PoolKey ,
283
281
) -> impl Future < Output = Result < Response < Body > , ClientError < B > > > + Unpin {
284
- let conn = self . connection_for ( req . uri ( ) . clone ( ) , pool_key) ;
282
+ let conn = self . connection_for ( pool_key) ;
285
283
286
284
let set_host = self . config . set_host ;
287
285
let executor = self . conn_builder . exec . clone ( ) ;
@@ -377,7 +375,6 @@ where
377
375
378
376
fn connection_for (
379
377
& self ,
380
- uri : Uri ,
381
378
pool_key : PoolKey ,
382
379
) -> impl Future < Output = Result < Pooled < PoolClient < B > > , ClientError < B > > > {
383
380
// This actually races 2 different futures to try to get a ready
@@ -394,7 +391,7 @@ where
394
391
// connection future is spawned into the runtime to complete,
395
392
// and then be inserted into the pool as an idle connection.
396
393
let checkout = self . pool . checkout ( pool_key. clone ( ) ) ;
397
- let connect = self . connect_to ( uri , pool_key) ;
394
+ let connect = self . connect_to ( pool_key) ;
398
395
399
396
let executor = self . conn_builder . exec . clone ( ) ;
400
397
// The order of the `select` is depended on below...
@@ -455,7 +452,6 @@ where
455
452
456
453
fn connect_to (
457
454
& self ,
458
- uri : Uri ,
459
455
pool_key : PoolKey ,
460
456
) -> impl Lazy < Output = crate :: Result < Pooled < PoolClient < B > > > > + Unpin {
461
457
let executor = self . conn_builder . exec . clone ( ) ;
@@ -464,7 +460,7 @@ where
464
460
let ver = self . config . ver ;
465
461
let is_ver_h2 = ver == Ver :: Http2 ;
466
462
let connector = self . connector . clone ( ) ;
467
- let dst = uri ;
463
+ let dst = domain_as_uri ( pool_key . clone ( ) ) ;
468
464
hyper_lazy ( move || {
469
465
// Try to take a "connecting lock".
470
466
//
@@ -794,22 +790,22 @@ fn authority_form(uri: &mut Uri) {
794
790
} ;
795
791
}
796
792
797
- fn extract_domain ( uri : & mut Uri , is_http_connect : bool ) -> crate :: Result < String > {
793
+ fn extract_domain ( uri : & mut Uri , is_http_connect : bool ) -> crate :: Result < PoolKey > {
798
794
let uri_clone = uri. clone ( ) ;
799
795
match ( uri_clone. scheme ( ) , uri_clone. authority ( ) ) {
800
- ( Some ( scheme) , Some ( auth) ) => Ok ( format ! ( "{}://{}" , scheme, auth) ) ,
796
+ ( Some ( scheme) , Some ( auth) ) => Ok ( ( scheme. clone ( ) , auth. clone ( ) ) ) ,
801
797
( None , Some ( auth) ) if is_http_connect => {
802
798
let scheme = match auth. port_u16 ( ) {
803
799
Some ( 443 ) => {
804
800
set_scheme ( uri, Scheme :: HTTPS ) ;
805
- "https"
801
+ Scheme :: HTTPS
806
802
}
807
803
_ => {
808
804
set_scheme ( uri, Scheme :: HTTP ) ;
809
- "http"
805
+ Scheme :: HTTP
810
806
}
811
807
} ;
812
- Ok ( format ! ( "{}://{}" , scheme, auth) )
808
+ Ok ( ( scheme, auth. clone ( ) ) )
813
809
}
814
810
_ => {
815
811
debug ! ( "Client requires absolute-form URIs, received: {:?}" , uri) ;
@@ -818,6 +814,15 @@ fn extract_domain(uri: &mut Uri, is_http_connect: bool) -> crate::Result<String>
818
814
}
819
815
}
820
816
817
+ fn domain_as_uri ( ( scheme, auth) : PoolKey ) -> Uri {
818
+ http:: uri:: Builder :: new ( )
819
+ . scheme ( scheme)
820
+ . authority ( auth)
821
+ . path_and_query ( "/" )
822
+ . build ( )
823
+ . expect ( "domain is valid Uri" )
824
+ }
825
+
821
826
fn set_scheme ( uri : & mut Uri , scheme : Scheme ) {
822
827
debug_assert ! (
823
828
uri. scheme( ) . is_none( ) ,
@@ -1126,7 +1131,8 @@ mod unit_tests {
1126
1131
#[ test]
1127
1132
fn test_extract_domain_connect_no_port ( ) {
1128
1133
let mut uri = "hyper.rs" . parse ( ) . unwrap ( ) ;
1129
- let domain = extract_domain ( & mut uri, true ) . expect ( "extract domain" ) ;
1130
- assert_eq ! ( domain, "http://hyper.rs" ) ;
1134
+ let ( scheme, host) = extract_domain ( & mut uri, true ) . expect ( "extract domain" ) ;
1135
+ assert_eq ! ( scheme, * "http" ) ;
1136
+ assert_eq ! ( host, "hyper.rs" ) ;
1131
1137
}
1132
1138
}
0 commit comments