@@ -27,7 +27,7 @@ pin_project_lite::pin_project! {
2727 where
2828 S : HttpService <Recv >,
2929 {
30- conn: Option < Http1Dispatcher <T , S :: ResBody , S > >,
30+ conn: Http1Dispatcher <T , S :: ResBody , S >,
3131 }
3232}
3333
9898 /// pending. If called after `Connection::poll` has resolved, this does
9999 /// nothing.
100100 pub fn graceful_shutdown ( mut self : Pin < & mut Self > ) {
101- match self . conn {
102- Some ( ref mut h1) => {
103- h1. disable_keep_alive ( ) ;
104- }
105- None => ( ) ,
106- }
101+ self . conn . disable_keep_alive ( ) ;
107102 }
108103
109104 /// Return the inner IO object, and additional information.
@@ -116,25 +111,13 @@ where
116111 /// # Panics
117112 /// This method will panic if this connection is using an h2 protocol.
118113 pub fn into_parts ( self ) -> Parts < I , S > {
119- self . try_into_parts ( )
120- . unwrap_or_else ( || panic ! ( "h2 cannot into_inner" ) )
121- }
122-
123- /// Return the inner IO object, and additional information, if available.
124- ///
125- ///
126- /// TODO:(mike) does this need to return none for h1 or is it expected to always be present? previously used an "unwrap"
127- /// This method will return a `None` if this connection is using an h2 protocol.
128- pub fn try_into_parts ( self ) -> Option < Parts < I , S > > {
129- self . conn . map ( |h1| {
130- let ( io, read_buf, dispatch) = h1. into_inner ( ) ;
131- Parts {
132- io,
133- read_buf,
134- service : dispatch. into_service ( ) ,
135- _inner : ( ) ,
136- }
137- } )
114+ let ( io, read_buf, dispatch) = self . conn . into_inner ( ) ;
115+ Parts {
116+ io,
117+ read_buf,
118+ service : dispatch. into_service ( ) ,
119+ _inner : ( ) ,
120+ }
138121 }
139122
140123 /// Poll the connection for completion, but without calling `shutdown`
@@ -150,7 +133,7 @@ where
150133 S :: Future : Unpin ,
151134 B : Unpin ,
152135 {
153- self . conn . as_mut ( ) . unwrap ( ) . poll_without_shutdown ( cx)
136+ self . conn . poll_without_shutdown ( cx)
154137 }
155138
156139 /// Prevent shutdown of the underlying IO object at the end of service the request,
@@ -165,15 +148,11 @@ where
165148 S :: Future : Unpin ,
166149 B : Unpin ,
167150 {
168- // TODO(mike): "new_without_shutdown_not_h1" is not possible here
169- let mut conn = Some ( self ) ;
151+ let mut zelf = Some ( self ) ;
170152 futures_util:: future:: poll_fn ( move |cx| {
171- ready ! ( conn . as_mut( ) . unwrap( ) . poll_without_shutdown( cx) ) ?;
153+ ready ! ( zelf . as_mut( ) . unwrap( ) . conn . poll_without_shutdown( cx) ) ?;
172154 Poll :: Ready (
173- conn. take ( )
174- . unwrap ( )
175- . try_into_parts ( )
176- . ok_or_else ( crate :: Error :: new_without_shutdown_not_h1) ,
155+ Ok ( zelf. take ( ) . unwrap ( ) . into_parts ( ) )
177156 )
178157 } )
179158 }
@@ -185,7 +164,7 @@ where
185164 where
186165 I : Send ,
187166 {
188- upgrades:: UpgradeableConnection { inner : self }
167+ upgrades:: UpgradeableConnection { inner : Some ( self ) }
189168 }
190169}
191170
@@ -201,7 +180,7 @@ where
201180 type Output = crate :: Result < ( ) > ;
202181
203182 fn poll ( mut self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
204- match ready ! ( Pin :: new( self . conn. as_mut ( ) . unwrap ( ) ) . poll( cx) ) {
183+ match ready ! ( Pin :: new( & mut self . conn) . poll( cx) ) {
205184 Ok ( done) => {
206185 match done {
207186 proto:: Dispatched :: Shutdown => { }
@@ -417,7 +396,7 @@ impl Builder {
417396 let sd = proto:: h1:: dispatch:: Server :: new ( service) ;
418397 let proto = proto:: h1:: Dispatcher :: new ( sd, conn) ;
419398 Connection {
420- conn : Some ( proto) ,
399+ conn : proto,
421400 }
422401 }
423402}
@@ -436,7 +415,7 @@ mod upgrades {
436415 where
437416 S : HttpService < Recv > ,
438417 {
439- pub ( super ) inner : Connection < T , S > ,
418+ pub ( super ) inner : Option < Connection < T , S > > ,
440419 }
441420
442421 impl < I , B , S > UpgradeableConnection < I , S >
@@ -452,7 +431,7 @@ mod upgrades {
452431 /// This `Connection` should continue to be polled until shutdown
453432 /// can finish.
454433 pub fn graceful_shutdown ( mut self : Pin < & mut Self > ) {
455- Pin :: new ( & mut self . inner ) . graceful_shutdown ( )
434+ Pin :: new ( self . inner . as_mut ( ) . unwrap ( ) ) . graceful_shutdown ( )
456435 }
457436 }
458437
@@ -467,10 +446,10 @@ mod upgrades {
467446 type Output = crate :: Result < ( ) > ;
468447
469448 fn poll ( mut self : Pin < & mut Self > , cx : & mut task:: Context < ' _ > ) -> Poll < Self :: Output > {
470- match ready ! ( Pin :: new( self . inner. conn . as_mut( ) . unwrap( ) ) . poll( cx) ) {
449+ match ready ! ( Pin :: new( & mut self . inner. as_mut( ) . unwrap( ) . conn ) . poll( cx) ) {
471450 Ok ( proto:: Dispatched :: Shutdown ) => Poll :: Ready ( Ok ( ( ) ) ) ,
472451 Ok ( proto:: Dispatched :: Upgrade ( pending) ) => {
473- let ( io, buf, _) = self . inner . conn . take ( ) . unwrap ( ) . into_inner ( ) ;
452+ let ( io, buf, _) = self . inner . take ( ) . unwrap ( ) . conn . into_inner ( ) ;
474453 pending. fulfill ( Upgraded :: new ( io, buf) ) ;
475454 Poll :: Ready ( Ok ( ( ) ) )
476455 }
0 commit comments