@@ -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.
@@ -334,7 +325,8 @@ impl<B> Clone for Http2SendRequest<B> {
334
325
impl < T , B > Connection < T , B >
335
326
where
336
327
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
337
- B : Payload + ' static ,
328
+ B : Payload + Unpin + ' static ,
329
+ B :: Data : Unpin ,
338
330
{
339
331
/// Return the inner IO object, and additional information.
340
332
///
@@ -365,29 +357,20 @@ where
365
357
/// Use [`poll_fn`](https://docs.rs/futures/0.1.25/futures/future/fn.poll_fn.html)
366
358
/// and [`try_ready!`](https://docs.rs/futures/0.1.25/futures/macro.try_ready.html)
367
359
/// to work with this function; or use the `without_shutdown` wrapper.
368
- pub fn poll_without_shutdown ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < crate :: Result < ( ) > >
369
- where
370
- B : Unpin ,
371
- {
360
+ pub fn poll_without_shutdown ( & mut self , cx : & mut task:: Context < ' _ > ) -> Poll < crate :: Result < ( ) > > {
372
361
match self . inner . as_mut ( ) . expect ( "already upgraded" ) {
373
362
& mut Either :: Left ( ref mut h1) => {
374
363
h1. poll_without_shutdown ( cx)
375
364
} ,
376
365
& mut Either :: Right ( ref mut h2) => {
377
- unimplemented ! ( "h2 poll_without_shutdown" ) ;
378
- /*
379
- h2.poll().map(|x| x.map(|_| ()))
380
- */
366
+ Pin :: new ( h2) . poll ( cx) . map_ok ( |_| ( ) )
381
367
}
382
368
}
383
369
}
384
370
385
371
/// Prevent shutdown of the underlying IO object at the end of service the request,
386
372
/// instead run `into_parts`. This is a convenience wrapper over `poll_without_shutdown`.
387
- pub fn without_shutdown ( self ) -> impl Future < Output =crate :: Result < Parts < T > > >
388
- where
389
- B : Unpin ,
390
- {
373
+ pub fn without_shutdown ( self ) -> impl Future < Output =crate :: Result < Parts < T > > > {
391
374
let mut conn = Some ( self ) ;
392
375
future:: poll_fn ( move |cx| -> Poll < crate :: Result < Parts < T > > > {
393
376
ready ! ( conn. as_mut( ) . unwrap( ) . poll_without_shutdown( cx) ) ?;
@@ -400,6 +383,7 @@ impl<T, B> Future for Connection<T, B>
400
383
where
401
384
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
402
385
B : Payload + Unpin + ' static ,
386
+ B :: Data : Unpin ,
403
387
{
404
388
type Output = crate :: Result < ( ) > ;
405
389
@@ -522,70 +506,46 @@ impl Builder {
522
506
}
523
507
524
508
/// Constructs a connection with the configured options and IO.
525
- #[ inline]
526
- pub fn handshake < T , B > ( & self , io : T ) -> Handshake < T , B >
509
+ pub async fn handshake < T , B > ( self , io : T ) -> crate :: Result < ( SendRequest < B > , Connection < T , B > ) >
527
510
where
528
511
T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
529
512
B : Payload + ' static ,
513
+ B :: Data : Unpin ,
530
514
{
531
515
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
516
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
517
let ( tx, rx) = dispatch:: channel ( ) ;
552
- let either = if !self . builder . http2 {
518
+ let either = if !self . http2 {
553
519
let mut conn = proto:: Conn :: new ( io) ;
554
- if !self . builder . h1_writev {
520
+ if !self . h1_writev {
555
521
conn. set_write_strategy_flatten ( ) ;
556
522
}
557
- if self . builder . h1_title_case_headers {
523
+ if self . h1_title_case_headers {
558
524
conn. set_title_case_headers ( ) ;
559
525
}
560
- if let Some ( sz) = self . builder . h1_read_buf_exact_size {
526
+ if let Some ( sz) = self . h1_read_buf_exact_size {
561
527
conn. set_read_buf_exact_size ( sz) ;
562
528
}
563
- if let Some ( max) = self . builder . h1_max_buf_size {
529
+ if let Some ( max) = self . h1_max_buf_size {
564
530
conn. set_max_buf_size ( max) ;
565
531
}
566
532
let cd = proto:: h1:: dispatch:: Client :: new ( rx) ;
567
533
let dispatch = proto:: h1:: Dispatcher :: new ( cd, conn) ;
568
534
Either :: Left ( dispatch)
569
535
} else {
570
- let h2 = proto:: h2:: Client :: new ( io, rx, & self . builder . h2_builder , self . builder . exec . clone ( ) ) ;
536
+ let h2 = proto:: h2:: client:: handshake ( io, rx, & self . h2_builder , self . exec . clone ( ) )
537
+ . await ?;
571
538
Either :: Right ( h2)
572
539
} ;
573
540
574
- Poll :: Ready ( Ok ( (
541
+ Ok ( (
575
542
SendRequest {
576
543
dispatch : tx,
577
544
} ,
578
545
Connection {
579
546
inner : Some ( either) ,
580
547
} ,
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 ( )
548
+ ) )
589
549
}
590
550
}
591
551
0 commit comments