From f1ab78a44cad49d38ad48539abb355c68a52b8dc Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 22 Apr 2021 15:26:38 +0100 Subject: [PATCH] propagate into change --- actix-http/src/body/body.rs | 2 ++ actix-http/src/body/message_body.rs | 21 +++++++++++++++++---- actix-http/src/builder.rs | 6 ++++-- actix-http/src/client/connection.rs | 3 ++- actix-http/src/client/h1proto.rs | 11 +++++++---- actix-http/src/client/h2proto.rs | 8 +++++--- actix-http/src/h1/service.rs | 10 +++++----- actix-http/src/h1/utils.rs | 4 ++-- actix-http/src/h2/dispatcher.rs | 2 +- actix-http/src/h2/service.rs | 15 ++++++++------- actix-http/src/response.rs | 3 ++- actix-http/src/service.rs | 1 + src/middleware/compat.rs | 6 ++++-- src/middleware/logger.rs | 6 +++++- src/response/response.rs | 6 +++++- src/server.rs | 3 ++- src/service.rs | 3 ++- src/test.rs | 12 ++++++++---- 18 files changed, 82 insertions(+), 40 deletions(-) diff --git a/actix-http/src/body/body.rs b/actix-http/src/body/body.rs index c86bf9234..e816f9cb4 100644 --- a/actix-http/src/body/body.rs +++ b/actix-http/src/body/body.rs @@ -72,6 +72,8 @@ impl MessageBody for Body { Poll::Ready(Some(Ok(mem::take(bin)))) } } + + // TODO: MSRV 1.51: poll_map_err Body::Message(body) => match ready!(body.as_mut().poll_next(cx)) { Some(Err(err)) => Poll::Ready(Some(Err(err.into()))), Some(Ok(val)) => Poll::Ready(Some(Ok(val))), diff --git a/actix-http/src/body/message_body.rs b/actix-http/src/body/message_body.rs index 4a7f7171f..21e54a7f1 100644 --- a/actix-http/src/body/message_body.rs +++ b/actix-http/src/body/message_body.rs @@ -45,7 +45,8 @@ impl MessageBody for () { impl MessageBody for Box where - T: MessageBody + Unpin, + T: MessageBody + Unpin, + T::Error: Into, { type Error = Error; @@ -57,11 +58,19 @@ where self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - Pin::new(self.get_mut().as_mut()).poll_next(cx) + match ready!(Pin::new(self.get_mut().as_mut()).poll_next(cx)) { + Some(Err(err)) => Poll::Ready(Some(Err(err.into()))), + Some(Ok(val)) => Poll::Ready(Some(Ok(val))), + None => Poll::Ready(None), + } } } -impl MessageBody for Pin> { +impl MessageBody for Pin> +where + T: MessageBody, + T::Error: Into, +{ type Error = Error; fn size(&self) -> BodySize { @@ -72,7 +81,11 @@ impl MessageBody for Pin> { mut self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll>> { - self.as_mut().poll_next(cx) + match ready!(self.as_mut().poll_next(cx)) { + Some(Err(err)) => Poll::Ready(Some(Err(err.into()))), + Some(Ok(val)) => Poll::Ready(Some(Ok(val))), + None => Poll::Ready(None), + } } } diff --git a/actix-http/src/builder.rs b/actix-http/src/builder.rs index 5e978cf1a..660cd9817 100644 --- a/actix-http/src/builder.rs +++ b/actix-http/src/builder.rs @@ -208,7 +208,7 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { let cfg = ServiceConfig::new( self.keep_alive, @@ -225,11 +225,13 @@ where /// Finish service configuration and create `HttpService` instance. pub fn finish(self, service: F) -> HttpService where - B: MessageBody + 'static, F: IntoServiceFactory, S::Error: Into + 'static, S::InitError: fmt::Debug, S::Response: Into> + 'static, + + B: MessageBody + 'static, + B::Error: Into, { let cfg = ServiceConfig::new( self.keep_alive, diff --git a/actix-http/src/client/connection.rs b/actix-http/src/client/connection.rs index ea08d58c7..a30f651ca 100644 --- a/actix-http/src/client/connection.rs +++ b/actix-http/src/client/connection.rs @@ -257,7 +257,8 @@ where ) -> LocalBoxFuture<'static, Result<(ResponseHead, Payload), SendRequestError>> where H: Into + 'static, - RB: MessageBody + 'static, + RB: MessageBody + 'static, + RB::Error: Into, { Box::pin(async move { match self { diff --git a/actix-http/src/client/h1proto.rs b/actix-http/src/client/h1proto.rs index 728748188..65a30748c 100644 --- a/actix-http/src/client/h1proto.rs +++ b/actix-http/src/client/h1proto.rs @@ -31,7 +31,8 @@ pub(crate) async fn send_request( ) -> Result<(ResponseHead, Payload), SendRequestError> where Io: ConnectionIo, - B: MessageBody, + B: MessageBody, + B::Error: Into, { // set request host header if !head.as_ref().headers.contains_key(HOST) @@ -153,7 +154,8 @@ pub(crate) async fn send_body( ) -> Result<(), SendRequestError> where Io: ConnectionIo, - B: MessageBody, + B: MessageBody, + B::Error: Into, { actix_rt::pin!(body); @@ -161,9 +163,10 @@ where while !eof { while !eof && !framed.as_ref().is_write_buf_full() { match poll_fn(|cx| body.as_mut().poll_next(cx)).await { - Some(result) => { - framed.as_mut().write(h1::Message::Chunk(Some(result?)))?; + Some(Ok(chunk)) => { + framed.as_mut().write(h1::Message::Chunk(Some(chunk)))?; } + Some(Err(err)) => return Err(err.into().into()), None => { eof = true; framed.as_mut().write(h1::Message::Chunk(None))?; diff --git a/actix-http/src/client/h2proto.rs b/actix-http/src/client/h2proto.rs index e852ec746..cf423ef12 100644 --- a/actix-http/src/client/h2proto.rs +++ b/actix-http/src/client/h2proto.rs @@ -30,7 +30,8 @@ pub(crate) async fn send_request( ) -> Result<(ResponseHead, Payload), SendRequestError> where Io: ConnectionIo, - B: MessageBody, + B: MessageBody, + B::Error: Into, { trace!("Sending client request: {:?} {:?}", head, body.size()); @@ -135,7 +136,8 @@ async fn send_body( mut send: SendStream, ) -> Result<(), SendRequestError> where - B: MessageBody, + B: MessageBody, + B::Error: Into, { let mut buf = None; actix_rt::pin!(body); @@ -146,7 +148,7 @@ where send.reserve_capacity(b.len()); buf = Some(b); } - Some(Err(e)) => return Err(e.into()), + Some(Err(e)) => return Err(e.into().into()), None => { if let Err(e) = send.send_data(Bytes::new(), true) { return Err(e.into()); diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index d988f3ccd..1ab85cbf3 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -66,7 +66,7 @@ where S::Response: Into>, B: MessageBody, - B: MessageBody, + B::Error: Into, X: ServiceFactory, X::Future: 'static, @@ -115,7 +115,7 @@ mod openssl { S::Response: Into>, B: MessageBody, - B: MessageBody, + B::Error: Into, X: ServiceFactory, X::Future: 'static, @@ -175,7 +175,7 @@ mod rustls { S::Response: Into>, B: MessageBody, - B: MessageBody, + B::Error: Into, X: ServiceFactory, X::Future: 'static, @@ -273,7 +273,7 @@ where S::InitError: fmt::Debug, B: MessageBody, - B: MessageBody, + B::Error: Into, X: ServiceFactory, X::Future: 'static, @@ -342,7 +342,7 @@ where S::Response: Into>, B: MessageBody, - B: MessageBody, + B::Error: Into, X: Service, X::Error: Into, diff --git a/actix-http/src/h1/utils.rs b/actix-http/src/h1/utils.rs index 8d101497c..73f01e913 100644 --- a/actix-http/src/h1/utils.rs +++ b/actix-http/src/h1/utils.rs @@ -22,7 +22,7 @@ pub struct SendResponse { impl SendResponse where B: MessageBody, - B: MessageBody, + B::Error: Into, { pub fn new(framed: Framed, response: Response) -> Self { let (res, body) = response.into_parts(); @@ -39,7 +39,7 @@ impl Future for SendResponse where T: AsyncRead + AsyncWrite + Unpin, B: MessageBody + Unpin, - B: MessageBody, + B::Error: Into, { type Output = Result, Error>; diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index fa26aa178..07636470b 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -76,7 +76,7 @@ where S::Response: Into> + 'static, B: MessageBody + 'static, - B::Error: Into + 'static, + B::Error: Into, { type Output = Result<(), DispatchError>; diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index 6ee9da646..a75abef7d 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -42,7 +42,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { /// Create new `H2Service` instance with config. pub(crate) fn with_config>( @@ -73,7 +73,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { /// Create plain TCP based service pub fn tcp( @@ -112,7 +112,7 @@ mod openssl { >::Future: 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { /// Create OpenSSL based service pub fn openssl( @@ -158,7 +158,7 @@ mod rustls { >::Future: 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { /// Create Rustls based service pub fn rustls( @@ -201,7 +201,7 @@ where >::Future: 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { type Response = (); type Error = DispatchError; @@ -263,7 +263,7 @@ where S::Future: 'static, S::Response: Into> + 'static, B: MessageBody + 'static, - B: MessageBody, + B::Error: Into, { type Response = (); type Error = DispatchError; @@ -327,7 +327,8 @@ where S::Error: Into + 'static, S::Future: 'static, S::Response: Into> + 'static, - B: MessageBody, + B: MessageBody, + B::Error: Into, { type Output = Result<(), DispatchError>; diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 80b540a3f..955bd5704 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -244,7 +244,8 @@ impl Response { impl fmt::Debug for Response where - B: MessageBody, + B: MessageBody, + B::Error: Into, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let res = writeln!( diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 62af89adb..d25a67a19 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -59,6 +59,7 @@ where S::Response: Into> + 'static, >::Future: 'static, B: MessageBody + 'static, + B::Error: Into, { /// Create new `HttpService` instance. pub fn new>(service: F) -> Self { diff --git a/src/middleware/compat.rs b/src/middleware/compat.rs index 3143f3c95..3a85591da 100644 --- a/src/middleware/compat.rs +++ b/src/middleware/compat.rs @@ -113,8 +113,10 @@ pub trait MapServiceResponseBody { fn map_body(self) -> ServiceResponse; } -impl + Unpin + 'static> MapServiceResponseBody - for ServiceResponse +impl MapServiceResponseBody for ServiceResponse +where + B: MessageBody + Unpin + 'static, + B::Error: Into, { fn map_body(self) -> ServiceResponse { self.map_body(|_, body| ResponseBody::Other(Body::from_message(body))) diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index a1ea8a71a..f32732724 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -326,7 +326,11 @@ impl PinnedDrop for StreamLog { } } -impl> MessageBody for StreamLog { +impl MessageBody for StreamLog +where + B: MessageBody, + B::Error: Into, +{ type Error = Error; fn size(&self) -> BodySize { diff --git a/src/response/response.rs b/src/response/response.rs index b1b49f820..6e09a0136 100644 --- a/src/response/response.rs +++ b/src/response/response.rs @@ -243,7 +243,11 @@ impl HttpResponse { } } -impl> fmt::Debug for HttpResponse { +impl fmt::Debug for HttpResponse +where + B: MessageBody, + B::Error: Into, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("HttpResponse") .field("error", &self.error) diff --git a/src/server.rs b/src/server.rs index 0d2ea4d08..6e11c642f 100644 --- a/src/server.rs +++ b/src/server.rs @@ -80,7 +80,8 @@ where >::Future: 'static, S::Service: 'static, // S::Service: 'static, - B: MessageBody + 'static, + B: MessageBody + 'static, + B::Error: Into, { /// Create new HTTP server with application factory pub fn new(factory: F) -> Self { diff --git a/src/service.rs b/src/service.rs index 2318ce5c2..0c03f84ad 100644 --- a/src/service.rs +++ b/src/service.rs @@ -445,7 +445,8 @@ impl From> for Response { impl fmt::Debug for ServiceResponse where - B: MessageBody, + B: MessageBody, + B::Error: Into, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let res = writeln!( diff --git a/src/test.rs b/src/test.rs index 2d02bd395..9fe5e9b5d 100644 --- a/src/test.rs +++ b/src/test.rs @@ -150,7 +150,8 @@ where pub async fn read_response(app: &S, req: Request) -> Bytes where S: Service, Error = Error>, - B: MessageBody + Unpin, + B: MessageBody + Unpin, + B::Error: Into, { let mut resp = app .call(req) @@ -195,7 +196,8 @@ where /// ``` pub async fn read_body(mut res: ServiceResponse) -> Bytes where - B: MessageBody + Unpin, + B: MessageBody + Unpin, + B::Error: Into, { let mut body = res.take_body(); let mut bytes = BytesMut::new(); @@ -244,7 +246,8 @@ where /// ``` pub async fn read_body_json(res: ServiceResponse) -> T where - B: MessageBody + Unpin, + B: MessageBody + Unpin, + B::Error: Into, T: DeserializeOwned, { let body = read_body(res).await; @@ -305,7 +308,8 @@ where pub async fn read_response_json(app: &S, req: Request) -> T where S: Service, Error = Error>, - B: MessageBody + Unpin, + B: MessageBody + Unpin, + B::Error: Into, T: DeserializeOwned, { let body = read_response(app, req).await;