@@ -506,46 +506,50 @@ impl Builder {
506
506
}
507
507
508
508
/// Constructs a connection with the configured options and IO.
509
- pub async fn handshake < T , B > ( self , io : T ) -> crate :: Result < ( SendRequest < B > , Connection < T , B > ) >
509
+ pub fn handshake < T , B > ( & self , io : T ) -> impl Future < Output = crate :: Result < ( SendRequest < B > , Connection < T , B > ) > >
510
510
where
511
511
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
512
512
B : Payload + ' static ,
513
513
B :: Data : Unpin ,
514
514
{
515
- trace ! ( "client handshake HTTP/{}" , if self . http2 { 2 } else { 1 } ) ;
516
-
517
- let ( tx, rx) = dispatch:: channel ( ) ;
518
- let either = if !self . http2 {
519
- let mut conn = proto:: Conn :: new ( io) ;
520
- if !self . h1_writev {
521
- conn. set_write_strategy_flatten ( ) ;
522
- }
523
- if self . h1_title_case_headers {
524
- conn. set_title_case_headers ( ) ;
525
- }
526
- if let Some ( sz) = self . h1_read_buf_exact_size {
527
- conn. set_read_buf_exact_size ( sz) ;
528
- }
529
- if let Some ( max) = self . h1_max_buf_size {
530
- conn. set_max_buf_size ( max) ;
531
- }
532
- let cd = proto:: h1:: dispatch:: Client :: new ( rx) ;
533
- let dispatch = proto:: h1:: Dispatcher :: new ( cd, conn) ;
534
- Either :: Left ( dispatch)
535
- } else {
536
- let h2 = proto:: h2:: client:: handshake ( io, rx, & self . h2_builder , self . exec . clone ( ) )
537
- . await ?;
538
- Either :: Right ( h2)
539
- } ;
540
-
541
- Ok ( (
542
- SendRequest {
543
- dispatch : tx,
544
- } ,
545
- Connection {
546
- inner : Some ( either) ,
547
- } ,
548
- ) )
515
+ let opts = self . clone ( ) ;
516
+
517
+ async move {
518
+ trace ! ( "client handshake HTTP/{}" , if opts. http2 { 2 } else { 1 } ) ;
519
+
520
+ let ( tx, rx) = dispatch:: channel ( ) ;
521
+ let either = if !opts. http2 {
522
+ let mut conn = proto:: Conn :: new ( io) ;
523
+ if !opts. h1_writev {
524
+ conn. set_write_strategy_flatten ( ) ;
525
+ }
526
+ if opts. h1_title_case_headers {
527
+ conn. set_title_case_headers ( ) ;
528
+ }
529
+ if let Some ( sz) = opts. h1_read_buf_exact_size {
530
+ conn. set_read_buf_exact_size ( sz) ;
531
+ }
532
+ if let Some ( max) = opts. h1_max_buf_size {
533
+ conn. set_max_buf_size ( max) ;
534
+ }
535
+ let cd = proto:: h1:: dispatch:: Client :: new ( rx) ;
536
+ let dispatch = proto:: h1:: Dispatcher :: new ( cd, conn) ;
537
+ Either :: Left ( dispatch)
538
+ } else {
539
+ let h2 = proto:: h2:: client:: handshake ( io, rx, & opts. h2_builder , opts. exec . clone ( ) )
540
+ . await ?;
541
+ Either :: Right ( h2)
542
+ } ;
543
+
544
+ Ok ( (
545
+ SendRequest {
546
+ dispatch : tx,
547
+ } ,
548
+ Connection {
549
+ inner : Some ( either) ,
550
+ } ,
551
+ ) )
552
+ }
549
553
}
550
554
}
551
555
0 commit comments