@@ -236,7 +236,8 @@ pub struct Connection<T, B: Buf = Bytes> {
236236#[ derive( Debug ) ]
237237#[ must_use = "futures do nothing unless polled" ]
238238pub struct ResponseFuture {
239- inner : proto:: OpaqueStreamRef ,
239+ inner : Option < proto:: OpaqueStreamRef > ,
240+ stream_id : crate :: StreamId ,
240241 push_promise_consumed : bool ,
241242}
242243
@@ -517,15 +518,16 @@ where
517518 self . inner
518519 . send_request ( request, end_of_stream, self . pending . as_ref ( ) )
519520 . map_err ( Into :: into)
520- . map ( |( stream, is_full) | {
521+ . map ( |( stream, response , is_full) | {
521522 if stream. is_pending_open ( ) && is_full {
522523 // Only prevent sending another request when the request queue
523524 // is not full.
524525 self . pending = Some ( stream. clone_to_opaque ( ) ) ;
525526 }
526527
527528 let response = ResponseFuture {
528- inner : stream. clone_to_opaque ( ) ,
529+ stream_id : crate :: StreamId :: from_internal ( response. stream_id ( ) ) ,
530+ inner : Some ( response) ,
529531 push_promise_consumed : false ,
530532 } ;
531533
@@ -1469,21 +1471,21 @@ impl Future for ResponseFuture {
14691471 type Output = Result < Response < RecvStream > , crate :: Error > ;
14701472
14711473 fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
1472- let ( parts, _) = ready ! ( self . inner. poll_response( cx) ) ?. into_parts ( ) ;
1473- let body = RecvStream :: new ( FlowControl :: new ( self . inner . clone ( ) ) ) ;
1474+ let inner = self
1475+ . inner
1476+ . as_mut ( )
1477+ . expect ( "ResponseFuture polled after completion" ) ;
1478+ let ( parts, _) = ready ! ( inner. poll_response( cx) ) ?. into_parts ( ) ;
1479+ let body = RecvStream :: new ( FlowControl :: new ( self . inner . take ( ) . unwrap ( ) ) ) ;
14741480
14751481 Poll :: Ready ( Ok ( Response :: from_parts ( parts, body) ) )
14761482 }
14771483}
14781484
14791485impl ResponseFuture {
14801486 /// Returns the stream ID of the response stream.
1481- ///
1482- /// # Panics
1483- ///
1484- /// If the lock on the stream store has been poisoned.
14851487 pub fn stream_id ( & self ) -> crate :: StreamId {
1486- crate :: StreamId :: from_internal ( self . inner . stream_id ( ) )
1488+ self . stream_id
14871489 }
14881490
14891491 /// Polls for informational responses (1xx status codes).
@@ -1498,7 +1500,11 @@ impl ResponseFuture {
14981500 & mut self ,
14991501 cx : & mut Context < ' _ > ,
15001502 ) -> Poll < Option < Result < Response < ( ) > , crate :: Error > > > {
1501- self . inner . poll_informational ( cx) . map_err ( Into :: into)
1503+ self . inner
1504+ . as_mut ( )
1505+ . expect ( "ResponseFuture polled after completion" )
1506+ . poll_informational ( cx)
1507+ . map_err ( Into :: into)
15021508 }
15031509
15041510 /// Returns a stream of PushPromises
@@ -1513,7 +1519,7 @@ impl ResponseFuture {
15131519 }
15141520 self . push_promise_consumed = true ;
15151521 PushPromises {
1516- inner : self . inner . clone ( ) ,
1522+ inner : self . inner . as_ref ( ) . unwrap ( ) . clone ( ) ,
15171523 }
15181524 }
15191525}
@@ -1535,7 +1541,8 @@ impl PushPromises {
15351541 Poll :: Ready ( Some ( Ok ( ( request, response) ) ) ) => {
15361542 let response = PushedResponseFuture {
15371543 inner : ResponseFuture {
1538- inner : response,
1544+ stream_id : crate :: StreamId :: from_internal ( response. stream_id ( ) ) ,
1545+ inner : Some ( response) ,
15391546 push_promise_consumed : false ,
15401547 } ,
15411548 } ;
@@ -1589,10 +1596,6 @@ impl Future for PushedResponseFuture {
15891596
15901597impl PushedResponseFuture {
15911598 /// Returns the stream ID of the response stream.
1592- ///
1593- /// # Panics
1594- ///
1595- /// If the lock on the stream store has been poisoned.
15961599 pub fn stream_id ( & self ) -> crate :: StreamId {
15971600 self . inner . stream_id ( )
15981601 }
0 commit comments