11use std:: cell:: { Cell , RefCell } ;
2- use std:: { error:: Error , fmt, future:: poll_fn, io, marker, mem, rc:: Rc , task:: Context } ;
2+ use std:: {
3+ error:: Error as StdError , fmt, future:: poll_fn, io, marker, mem, rc:: Rc , task:: Context ,
4+ } ;
35
46use ntex_h2:: { self as h2, frame:: StreamId , server} ;
57
68use crate :: channel:: oneshot;
9+ use crate :: error:: Error ;
710use crate :: http:: body:: { BodySize , MessageBody } ;
811use crate :: http:: config:: DispatcherConfig ;
912use crate :: http:: error:: { DispatchError , H2Error , ResponseError } ;
@@ -62,7 +65,7 @@ mod openssl {
6265 B : MessageBody ,
6366 C : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck >
6467 + ' static ,
65- C :: Error : Error ,
68+ C :: Error : StdError ,
6669 C :: InitError : fmt:: Debug ,
6770 {
6871 /// Create ssl based service
@@ -103,7 +106,7 @@ mod rustls {
103106 B : MessageBody ,
104107 C : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck >
105108 + ' static ,
106- C :: Error : Error ,
109+ C :: Error : StdError ,
107110 C :: InitError : fmt:: Debug ,
108111 {
109112 /// Create openssl based service
@@ -137,14 +140,14 @@ where
137140 S :: InitError : fmt:: Debug ,
138141 B : MessageBody ,
139142 C : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck > ,
140- C :: Error : Error ,
143+ C :: Error : StdError ,
141144 C :: InitError : fmt:: Debug ,
142145{
143146 /// Provide http/2 control service
144147 pub fn control < CT > ( self , ctl : CT ) -> H2Service < F , S , B , CT >
145148 where
146149 CT : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck > ,
147- CT :: Error : Error ,
150+ CT :: Error : StdError ,
148151 CT :: InitError : fmt:: Debug ,
149152 {
150153 H2Service {
@@ -164,7 +167,7 @@ where
164167 S :: Response : Into < Response < B > > ,
165168 B : MessageBody ,
166169 C : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck > + ' static ,
167- C :: Error : Error ,
170+ C :: Error : StdError ,
168171 C :: InitError : fmt:: Debug ,
169172{
170173 type Response = ( ) ;
@@ -213,7 +216,7 @@ where
213216 S :: Response : Into < Response < B > > ,
214217 B : MessageBody ,
215218 C : ServiceFactory < h2:: Control < H2Error > , SharedCfg , Response = h2:: ControlAck > + ' static ,
216- C :: Error : Error ,
219+ C :: Error : StdError ,
217220 C :: InitError : fmt:: Debug ,
218221{
219222 type Response = ( ) ;
@@ -311,7 +314,7 @@ where
311314 S :: Response : Into < Response < B > > ,
312315 B : MessageBody ,
313316 C2 : Service < h2:: Control < H2Error > , Response = h2:: ControlAck > + ' static ,
314- C2 :: Error : Error ,
317+ C2 :: Error : StdError ,
315318{
316319 let ioref = io. get_ref ( ) ;
317320
@@ -415,7 +418,9 @@ where
415418 h2:: StreamEof :: Trailers ( _) => {
416419 sender. feed_eof ( Bytes :: new ( ) ) ;
417420 }
418- h2:: StreamEof :: Error ( err) => sender. set_error ( err. into ( ) ) ,
421+ h2:: StreamEof :: Error ( err) => {
422+ sender. set_error ( err. into_error ( ) . into ( ) ) ;
423+ }
419424 }
420425 }
421426 return Ok ( ( ) ) ;
@@ -480,9 +485,13 @@ where
480485
481486 let hdrs = mem:: replace ( & mut head. headers , HeaderMap :: new ( ) ) ;
482487 if size. is_eof ( ) || is_head_req {
483- stream. send_response ( head. status , hdrs, true ) ?;
488+ stream
489+ . send_response ( head. status , hdrs, true )
490+ . map_err ( Error :: into_error) ?;
484491 } else {
485- stream. send_response ( head. status , hdrs, false ) ?;
492+ stream
493+ . send_response ( head. status , hdrs, false )
494+ . map_err ( Error :: into_error) ?;
486495
487496 loop {
488497 match poll_fn ( |cx| body. poll_next_chunk ( cx) ) . await {
@@ -492,7 +501,10 @@ where
492501 self . io. tag( ) ,
493502 stream. id( )
494503 ) ;
495- stream. send_payload ( Bytes :: new ( ) , true ) . await ?;
504+ stream
505+ . send_payload ( Bytes :: new ( ) , true )
506+ . await
507+ . map_err ( Error :: into_error) ?;
496508 break ;
497509 }
498510 Some ( Ok ( chunk) ) => {
@@ -503,7 +515,10 @@ where
503515 chunk. len( )
504516 ) ;
505517 if !chunk. is_empty ( ) {
506- stream. send_payload ( chunk, false ) . await ?;
518+ stream
519+ . send_payload ( chunk, false )
520+ . await
521+ . map_err ( Error :: into_error) ?;
507522 }
508523 }
509524 Some ( Err ( e) ) => {
0 commit comments