Loading rust-runtime/smithy-http-tower/src/parse_response.rs +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ impl<S, O, T, E, B, R> tower::Service<operation::Operation<O, R>> for ParseRespo where S: Service<operation::Request, Response = http::Response<B>, Error = SendOperationError>, S::Future: 'static, B: http_body::Body + Unpin + 'static, B: http_body::Body + 'static, B::Error: Into<BoxError>, O: ParseHttpResponse<B, Output = Result<T, E>> + 'static, E: Error, Loading rust-runtime/smithy-http/src/middleware.rs +15 −8 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use crate::pin_mut; use crate::response::ParseHttpResponse; use crate::result::{SdkError, SdkSuccess}; use bytes::{Buf, Bytes}; use http::Response; use http_body::Body; use std::error::Error; Loading @@ -39,7 +40,7 @@ impl ResponseBody { pub fn bytes(&self) -> Option<&[u8]> { match &self.0 { Inner::Bytes(bytes) => Some(&bytes), _ => None _ => None, } } } Loading @@ -52,7 +53,6 @@ enum Inner { Err, } type BoxError = Box<dyn Error + Send + Sync>; /// [`MapRequest`] defines a synchronous middleware that transforms an [`operation::Request`]. Loading Loading @@ -111,27 +111,34 @@ pub async fn load_response<B, T, E, O>( handler: &O, ) -> Result<SdkSuccess<T>, SdkError<E>> where B: http_body::Body + Unpin, B: http_body::Body, B::Error: Into<BoxError>, O: ParseHttpResponse<B, Output = Result<T, E>>, { if let Some(parsed_response) = handler.parse_unloaded(&mut response) { return sdk_result(parsed_response, response.map(|_|ResponseBody(Inner::Streaming))); return sdk_result( parsed_response, response.map(|_| ResponseBody(Inner::Streaming)), ); } let (parts, body) = response.into_parts(); let body = match read_body(response.body_mut()).await { let body = match read_body(body).await { Ok(body) => body, Err(e) => { return Err(SdkError::ResponseError { raw: response.map(|_|ResponseBody(Inner::Err)), raw: Response::from_parts(parts, ResponseBody(Inner::Err)), err: e.into(), }); } }; let response = response.map(|_| Bytes::from(body)); let response = Response::from_parts(parts, Bytes::from(body)); let parsed = handler.parse_loaded(&response); sdk_result(parsed, response.map(|body|ResponseBody(Inner::Bytes(body)))) sdk_result( parsed, response.map(|body| ResponseBody(Inner::Bytes(body))), ) } async fn read_body<B: http_body::Body>(body: B) -> Result<Vec<u8>, B::Error> { Loading rust-runtime/smithy-http/src/result.rs +5 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0. */ use crate::middleware::ResponseBody; use std::error::Error; use std::fmt; use std::fmt::{Debug, Display, Formatter}; use crate::middleware::ResponseBody; type BoxError = Box<dyn Error + Send + Sync>; /// Successful Sdk Result Loading Loading @@ -34,7 +34,10 @@ pub enum SdkError<E> { }, /// An error response was received from the service ServiceError { err: E, raw: http::Response<ResponseBody> }, ServiceError { err: E, raw: http::Response<ResponseBody>, }, } impl<E> Display for SdkError<E> Loading Loading
rust-runtime/smithy-http-tower/src/parse_response.rs +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ impl<S, O, T, E, B, R> tower::Service<operation::Operation<O, R>> for ParseRespo where S: Service<operation::Request, Response = http::Response<B>, Error = SendOperationError>, S::Future: 'static, B: http_body::Body + Unpin + 'static, B: http_body::Body + 'static, B::Error: Into<BoxError>, O: ParseHttpResponse<B, Output = Result<T, E>> + 'static, E: Error, Loading
rust-runtime/smithy-http/src/middleware.rs +15 −8 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use crate::pin_mut; use crate::response::ParseHttpResponse; use crate::result::{SdkError, SdkSuccess}; use bytes::{Buf, Bytes}; use http::Response; use http_body::Body; use std::error::Error; Loading @@ -39,7 +40,7 @@ impl ResponseBody { pub fn bytes(&self) -> Option<&[u8]> { match &self.0 { Inner::Bytes(bytes) => Some(&bytes), _ => None _ => None, } } } Loading @@ -52,7 +53,6 @@ enum Inner { Err, } type BoxError = Box<dyn Error + Send + Sync>; /// [`MapRequest`] defines a synchronous middleware that transforms an [`operation::Request`]. Loading Loading @@ -111,27 +111,34 @@ pub async fn load_response<B, T, E, O>( handler: &O, ) -> Result<SdkSuccess<T>, SdkError<E>> where B: http_body::Body + Unpin, B: http_body::Body, B::Error: Into<BoxError>, O: ParseHttpResponse<B, Output = Result<T, E>>, { if let Some(parsed_response) = handler.parse_unloaded(&mut response) { return sdk_result(parsed_response, response.map(|_|ResponseBody(Inner::Streaming))); return sdk_result( parsed_response, response.map(|_| ResponseBody(Inner::Streaming)), ); } let (parts, body) = response.into_parts(); let body = match read_body(response.body_mut()).await { let body = match read_body(body).await { Ok(body) => body, Err(e) => { return Err(SdkError::ResponseError { raw: response.map(|_|ResponseBody(Inner::Err)), raw: Response::from_parts(parts, ResponseBody(Inner::Err)), err: e.into(), }); } }; let response = response.map(|_| Bytes::from(body)); let response = Response::from_parts(parts, Bytes::from(body)); let parsed = handler.parse_loaded(&response); sdk_result(parsed, response.map(|body|ResponseBody(Inner::Bytes(body)))) sdk_result( parsed, response.map(|body| ResponseBody(Inner::Bytes(body))), ) } async fn read_body<B: http_body::Body>(body: B) -> Result<Vec<u8>, B::Error> { Loading
rust-runtime/smithy-http/src/result.rs +5 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0. */ use crate::middleware::ResponseBody; use std::error::Error; use std::fmt; use std::fmt::{Debug, Display, Formatter}; use crate::middleware::ResponseBody; type BoxError = Box<dyn Error + Send + Sync>; /// Successful Sdk Result Loading Loading @@ -34,7 +34,10 @@ pub enum SdkError<E> { }, /// An error response was received from the service ServiceError { err: E, raw: http::Response<ResponseBody> }, ServiceError { err: E, raw: http::Response<ResponseBody>, }, } impl<E> Display for SdkError<E> Loading