@@ -32,18 +32,19 @@ type Http1Dispatcher<T, B, R> = proto::dispatch::Dispatcher<
32
32
> ;
33
33
type ConnEither < T , B > = Either <
34
34
Http1Dispatcher < T , B , proto:: h1:: ClientTransaction > ,
35
- proto:: h2:: Client < T , B > ,
35
+ proto:: h2:: ClientTask < B > ,
36
36
> ;
37
37
38
- /// Returns a `Handshake` future over some IO.
38
+ /// Returns a handshake future over some IO.
39
39
///
40
40
/// This is a shortcut for `Builder::new().handshake(io)`.
41
- pub fn handshake < T > ( io : T ) -> Handshake < T , crate :: Body >
41
+ pub async fn handshake < T > ( io : T ) -> crate :: Result < ( SendRequest < crate :: Body > , Connection < T , crate :: Body > ) >
42
42
where
43
43
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
44
44
{
45
45
Builder :: new ( )
46
46
. handshake ( io)
47
+ . await
47
48
}
48
49
49
50
/// The sender side of an established connection.
68
69
69
70
/// A builder to configure an HTTP connection.
70
71
///
71
- /// After setting options, the builder is used to create a `Handshake` future.
72
+ /// After setting options, the builder is used to create a handshake future.
72
73
#[ derive( Clone , Debug ) ]
73
74
pub struct Builder {
74
75
pub ( super ) exec : Exec ,
@@ -80,16 +81,6 @@ pub struct Builder {
80
81
h2_builder : h2:: client:: Builder ,
81
82
}
82
83
83
- /// A future setting up HTTP over an IO object.
84
- ///
85
- /// If successful, yields a `(SendRequest, Connection)` pair.
86
- #[ must_use = "futures do nothing unless polled" ]
87
- pub struct Handshake < T , B > {
88
- builder : Builder ,
89
- io : Option < T > ,
90
- _marker : PhantomData < fn ( B ) > ,
91
- }
92
-
93
84
/// A future returned by `SendRequest::send_request`.
94
85
///
95
86
/// Yields a `Response` if successful.
@@ -400,6 +391,7 @@ impl<T, B> Future for Connection<T, B>
400
391
where
401
392
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
402
393
B : Payload + Unpin + ' static ,
394
+ B :: Data : Unpin ,
403
395
{
404
396
type Output = crate :: Result < ( ) > ;
405
397
@@ -522,70 +514,46 @@ impl Builder {
522
514
}
523
515
524
516
/// Constructs a connection with the configured options and IO.
525
- #[ inline]
526
- pub fn handshake < T , B > ( & self , io : T ) -> Handshake < T , B >
517
+ pub async fn handshake < T , B > ( self , io : T ) -> crate :: Result < ( SendRequest < B > , Connection < T , B > ) >
527
518
where
528
519
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
529
520
B : Payload + ' static ,
521
+ B :: Data : Unpin ,
530
522
{
531
523
trace ! ( "client handshake HTTP/{}" , if self . http2 { 2 } else { 1 } ) ;
532
- Handshake {
533
- builder : self . clone ( ) ,
534
- io : Some ( io) ,
535
- _marker : PhantomData ,
536
- }
537
- }
538
- }
539
-
540
- // ===== impl Handshake
541
-
542
- impl < T , B > Future for Handshake < T , B >
543
- where
544
- T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
545
- B : Payload + ' static ,
546
- {
547
- type Output = crate :: Result < ( SendRequest < B > , Connection < T , B > ) > ;
548
524
549
- fn poll ( mut self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
550
- let io = self . io . take ( ) . expect ( "polled more than once" ) ;
551
525
let ( tx, rx) = dispatch:: channel ( ) ;
552
- let either = if !self . builder . http2 {
526
+ let either = if !self . http2 {
553
527
let mut conn = proto:: Conn :: new ( io) ;
554
- if !self . builder . h1_writev {
528
+ if !self . h1_writev {
555
529
conn. set_write_strategy_flatten ( ) ;
556
530
}
557
- if self . builder . h1_title_case_headers {
531
+ if self . h1_title_case_headers {
558
532
conn. set_title_case_headers ( ) ;
559
533
}
560
- if let Some ( sz) = self . builder . h1_read_buf_exact_size {
534
+ if let Some ( sz) = self . h1_read_buf_exact_size {
561
535
conn. set_read_buf_exact_size ( sz) ;
562
536
}
563
- if let Some ( max) = self . builder . h1_max_buf_size {
537
+ if let Some ( max) = self . h1_max_buf_size {
564
538
conn. set_max_buf_size ( max) ;
565
539
}
566
540
let cd = proto:: h1:: dispatch:: Client :: new ( rx) ;
567
541
let dispatch = proto:: h1:: Dispatcher :: new ( cd, conn) ;
568
542
Either :: Left ( dispatch)
569
543
} else {
570
- let h2 = proto:: h2:: Client :: new ( io, rx, & self . builder . h2_builder , self . builder . exec . clone ( ) ) ;
544
+ let h2 = proto:: h2:: client:: handshake ( io, rx, & self . h2_builder , self . exec . clone ( ) )
545
+ . await ?;
571
546
Either :: Right ( h2)
572
547
} ;
573
548
574
- Poll :: Ready ( Ok ( (
549
+ Ok ( (
575
550
SendRequest {
576
551
dispatch : tx,
577
552
} ,
578
553
Connection {
579
554
inner : Some ( either) ,
580
555
} ,
581
- ) ) )
582
- }
583
- }
584
-
585
- impl < T , B > fmt:: Debug for Handshake < T , B > {
586
- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
587
- f. debug_struct ( "Handshake" )
588
- . finish ( )
556
+ ) )
589
557
}
590
558
}
591
559
0 commit comments