@@ -10,6 +10,7 @@ use crate::common::{task, Future, Pin, Poll, Unpin};
10
10
use crate :: proto:: {
11
11
BodyLength , Conn , Dispatched , MessageHead , RequestHead ,
12
12
} ;
13
+ use crate :: upgrade:: OnUpgrade ;
13
14
14
15
pub ( crate ) struct Dispatcher < D , Bs : HttpBody , I , T > {
15
16
conn : Conn < I , Bs :: Data , T > ,
@@ -243,8 +244,8 @@ where
243
244
}
244
245
// dispatch is ready for a message, try to read one
245
246
match ready ! ( self . conn. poll_read_head( cx) ) {
246
- Some ( Ok ( ( head, body_len, wants) ) ) => {
247
- let mut body = match body_len {
247
+ Some ( Ok ( ( mut head, body_len, wants) ) ) => {
248
+ let body = match body_len {
248
249
DecodedLength :: ZERO => Body :: empty ( ) ,
249
250
other => {
250
251
let ( tx, rx) = Body :: new_channel ( other, wants. contains ( Wants :: EXPECT ) ) ;
@@ -253,7 +254,10 @@ where
253
254
}
254
255
} ;
255
256
if wants. contains ( Wants :: UPGRADE ) {
256
- body. set_on_upgrade ( self . conn . on_upgrade ( ) ) ;
257
+ let upgrade = self . conn . on_upgrade ( ) ;
258
+ debug_assert ! ( !upgrade. is_none( ) , "empty upgrade" ) ;
259
+ debug_assert ! ( head. extensions. get:: <OnUpgrade >( ) . is_none( ) , "OnUpgrade already set" ) ;
260
+ head. extensions . insert ( upgrade) ;
257
261
}
258
262
self . dispatch . recv_msg ( Ok ( ( head, body) ) ) ?;
259
263
Poll :: Ready ( Ok ( ( ) ) )
@@ -488,6 +492,7 @@ cfg_server! {
488
492
version: parts. version,
489
493
subject: parts. status,
490
494
headers: parts. headers,
495
+ extensions: http:: Extensions :: default ( ) ,
491
496
} ;
492
497
Poll :: Ready ( Some ( Ok ( ( head, body) ) ) )
493
498
} else {
@@ -506,6 +511,7 @@ cfg_server! {
506
511
* req. uri_mut( ) = msg. subject. 1 ;
507
512
* req. headers_mut( ) = msg. headers;
508
513
* req. version_mut( ) = msg. version;
514
+ * req. extensions_mut( ) = msg. extensions;
509
515
let fut = self . service. call( req) ;
510
516
self . in_flight. set( Some ( fut) ) ;
511
517
Ok ( ( ) )
@@ -570,6 +576,7 @@ cfg_client! {
570
576
version: parts. version,
571
577
subject: crate :: proto:: RequestLine ( parts. method, parts. uri) ,
572
578
headers: parts. headers,
579
+ extensions: http:: Extensions :: default ( ) ,
573
580
} ;
574
581
* this. callback = Some ( cb) ;
575
582
Poll :: Ready ( Some ( Ok ( ( head, body) ) ) )
@@ -594,6 +601,7 @@ cfg_client! {
594
601
* res. status_mut( ) = msg. subject;
595
602
* res. headers_mut( ) = msg. headers;
596
603
* res. version_mut( ) = msg. version;
604
+ * res. extensions_mut( ) = msg. extensions;
597
605
cb. send( Ok ( res) ) ;
598
606
Ok ( ( ) )
599
607
} else {
0 commit comments