22//!
33//! See [`Interceptor`] for more details.
44
5- use crate :: { request:: SanitizeHeaders , Status } ;
5+ use crate :: {
6+ body:: { boxed, BoxBody } ,
7+ request:: SanitizeHeaders ,
8+ Status ,
9+ } ;
610use bytes:: Bytes ;
711use pin_project:: pin_project;
812use std:: {
@@ -145,15 +149,16 @@ where
145149 F : Interceptor ,
146150 S : Service < http:: Request < ReqBody > , Response = http:: Response < ResBody > > ,
147151 S :: Error : Into < crate :: Error > ,
152+ ResBody : http_body:: Body < Data = bytes:: Bytes > + Send + ' static ,
148153 ResBody :: Error : Into < crate :: Error > ,
149154{
150- type Response = http:: Response < ResBody > ;
151- type Error = crate :: Error ;
155+ type Response = http:: Response < BoxBody > ;
156+ type Error = S :: Error ;
152157 type Future = ResponseFuture < S :: Future > ;
153158
154159 #[ inline]
155160 fn poll_ready ( & mut self , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
156- self . inner . poll_ready ( cx) . map_err ( Into :: into )
161+ self . inner . poll_ready ( cx)
157162 }
158163
159164 fn call ( & mut self , req : http:: Request < ReqBody > ) -> Self :: Future {
@@ -171,7 +176,7 @@ where
171176 let req = req. into_http ( uri, SanitizeHeaders :: No ) ;
172177 ResponseFuture :: future ( self . inner . call ( req) )
173178 }
174- Err ( status) => ResponseFuture :: error ( status) ,
179+ Err ( status) => ResponseFuture :: status ( status) ,
175180 }
176181 }
177182}
@@ -200,9 +205,9 @@ impl<F> ResponseFuture<F> {
200205 }
201206 }
202207
203- fn error ( status : Status ) -> Self {
208+ fn status ( status : Status ) -> Self {
204209 Self {
205- kind : Kind :: Error ( Some ( status) ) ,
210+ kind : Kind :: Status ( Some ( status) ) ,
206211 }
207212 }
208213}
@@ -211,7 +216,7 @@ impl<F> ResponseFuture<F> {
211216#[ derive( Debug ) ]
212217enum Kind < F > {
213218 Future ( #[ pin] F ) ,
214- Error ( Option < Status > ) ,
219+ Status ( Option < Status > ) ,
215220}
216221
217222impl < F , E , B > Future for ResponseFuture < F >
@@ -221,14 +226,20 @@ where
221226 B : Default + http_body:: Body < Data = Bytes > + Send + ' static ,
222227 B :: Error : Into < crate :: Error > ,
223228{
224- type Output = Result < http:: Response < B > , crate :: Error > ;
229+ type Output = Result < http:: Response < BoxBody > , E > ;
225230
226231 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
227232 match self . project ( ) . kind . project ( ) {
228- KindProj :: Future ( future) => future. poll ( cx) . map_err ( Into :: into) ,
229- KindProj :: Error ( status) => {
230- let response = status. take ( ) . unwrap ( ) . to_http ( ) . map ( |_| B :: default ( ) ) ;
231-
233+ KindProj :: Future ( future) => future
234+ . poll ( cx)
235+ . map ( |result| result. map ( |res| res. map ( boxed) ) ) ,
236+ KindProj :: Status ( status) => {
237+ let response = status
238+ . take ( )
239+ . unwrap ( )
240+ . to_http ( )
241+ . map ( |_| B :: default ( ) )
242+ . map ( boxed) ;
232243 Poll :: Ready ( Ok ( response) )
233244 }
234245 }
0 commit comments