@@ -27,7 +27,7 @@ pin_project_lite::pin_project! {
27
27
where
28
28
S : HttpService <Recv >,
29
29
{
30
- conn: Option < Http1Dispatcher <T , S :: ResBody , S > >,
30
+ conn: Http1Dispatcher <T , S :: ResBody , S >,
31
31
}
32
32
}
33
33
98
98
/// pending. If called after `Connection::poll` has resolved, this does
99
99
/// nothing.
100
100
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 ( ) ;
107
102
}
108
103
109
104
/// Return the inner IO object, and additional information.
@@ -116,25 +111,13 @@ where
116
111
/// # Panics
117
112
/// This method will panic if this connection is using an h2 protocol.
118
113
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
+ }
138
121
}
139
122
140
123
/// Poll the connection for completion, but without calling `shutdown`
@@ -150,7 +133,7 @@ where
150
133
S :: Future : Unpin ,
151
134
B : Unpin ,
152
135
{
153
- self . conn . as_mut ( ) . unwrap ( ) . poll_without_shutdown ( cx)
136
+ self . conn . poll_without_shutdown ( cx)
154
137
}
155
138
156
139
/// Prevent shutdown of the underlying IO object at the end of service the request,
@@ -165,15 +148,11 @@ where
165
148
S :: Future : Unpin ,
166
149
B : Unpin ,
167
150
{
168
- // TODO(mike): "new_without_shutdown_not_h1" is not possible here
169
- let mut conn = Some ( self ) ;
151
+ let mut zelf = Some ( self ) ;
170
152
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) ) ?;
172
154
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 ( ) )
177
156
)
178
157
} )
179
158
}
@@ -185,7 +164,7 @@ where
185
164
where
186
165
I : Send ,
187
166
{
188
- upgrades:: UpgradeableConnection { inner : self }
167
+ upgrades:: UpgradeableConnection { inner : Some ( self ) }
189
168
}
190
169
}
191
170
@@ -201,7 +180,7 @@ where
201
180
type Output = crate :: Result < ( ) > ;
202
181
203
182
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) ) {
205
184
Ok ( done) => {
206
185
match done {
207
186
proto:: Dispatched :: Shutdown => { }
@@ -417,7 +396,7 @@ impl Builder {
417
396
let sd = proto:: h1:: dispatch:: Server :: new ( service) ;
418
397
let proto = proto:: h1:: Dispatcher :: new ( sd, conn) ;
419
398
Connection {
420
- conn : Some ( proto) ,
399
+ conn : proto,
421
400
}
422
401
}
423
402
}
@@ -436,7 +415,7 @@ mod upgrades {
436
415
where
437
416
S : HttpService < Recv > ,
438
417
{
439
- pub ( super ) inner : Connection < T , S > ,
418
+ pub ( super ) inner : Option < Connection < T , S > > ,
440
419
}
441
420
442
421
impl < I , B , S > UpgradeableConnection < I , S >
@@ -452,7 +431,7 @@ mod upgrades {
452
431
/// This `Connection` should continue to be polled until shutdown
453
432
/// can finish.
454
433
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 ( )
456
435
}
457
436
}
458
437
@@ -467,10 +446,10 @@ mod upgrades {
467
446
type Output = crate :: Result < ( ) > ;
468
447
469
448
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) ) {
471
450
Ok ( proto:: Dispatched :: Shutdown ) => Poll :: Ready ( Ok ( ( ) ) ) ,
472
451
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 ( ) ;
474
453
pending. fulfill ( Upgraded :: new ( io, buf) ) ;
475
454
Poll :: Ready ( Ok ( ( ) ) )
476
455
}
0 commit comments