message body error type downstream

This commit is contained in:
Rob Ede 2021-04-21 16:05:59 +01:00
parent b613c64abf
commit 2b818be18f
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
7 changed files with 19 additions and 13 deletions

View File

@ -85,7 +85,7 @@ where
S::InitError: fmt::Debug, S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody<Error = Error> + 'static,
{ {
start_with(TestServerConfig::default(), factory) start_with(TestServerConfig::default(), factory)
} }
@ -124,7 +124,7 @@ where
S::InitError: fmt::Debug, S::InitError: fmt::Debug,
S::Response: Into<Response<B>> + 'static, S::Response: Into<Response<B>> + 'static,
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
B: MessageBody + 'static, B: MessageBody<Error = Error> + 'static,
{ {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();

View File

@ -113,7 +113,9 @@ pub trait MapServiceResponseBody {
fn map_body(self) -> ServiceResponse; fn map_body(self) -> ServiceResponse;
} }
impl<B: MessageBody + Unpin + 'static> MapServiceResponseBody for ServiceResponse<B> { impl<B: MessageBody<Error = Error> + Unpin + 'static> MapServiceResponseBody
for ServiceResponse<B>
{
fn map_body(self) -> ServiceResponse { fn map_body(self) -> ServiceResponse {
self.map_body(|_, body| ResponseBody::Other(Body::from_message(body))) self.map_body(|_, body| ResponseBody::Other(Body::from_message(body)))
} }

View File

@ -22,10 +22,9 @@ use time::OffsetDateTime;
use crate::{ use crate::{
dev::{BodySize, MessageBody, ResponseBody}, dev::{BodySize, MessageBody, ResponseBody},
error::{Error, Result},
http::{HeaderName, StatusCode}, http::{HeaderName, StatusCode},
service::{ServiceRequest, ServiceResponse}, service::{ServiceRequest, ServiceResponse},
HttpResponse, Error, HttpResponse, Result,
}; };
/// Middleware for logging request and response summaries to the terminal. /// Middleware for logging request and response summaries to the terminal.
@ -327,7 +326,9 @@ impl<B> PinnedDrop for StreamLog<B> {
} }
} }
impl<B: MessageBody> MessageBody for StreamLog<B> { impl<B: MessageBody<Error = Error>> MessageBody for StreamLog<B> {
type Error = Error;
fn size(&self) -> BodySize { fn size(&self) -> BodySize {
self.body.size() self.body.size()
} }

View File

@ -243,7 +243,7 @@ impl<B> HttpResponse<B> {
} }
} }
impl<B: MessageBody> fmt::Debug for HttpResponse<B> { impl<B: MessageBody<Error = Error>> fmt::Debug for HttpResponse<B> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HttpResponse") f.debug_struct("HttpResponse")
.field("error", &self.error) .field("error", &self.error)

View File

@ -80,7 +80,7 @@ where
<S::Service as Service<Request>>::Future: 'static, <S::Service as Service<Request>>::Future: 'static,
S::Service: 'static, S::Service: 'static,
// S::Service: 'static, // S::Service: 'static,
B: MessageBody + 'static, B: MessageBody<Error = Error> + 'static,
{ {
/// Create new HTTP server with application factory /// Create new HTTP server with application factory
pub fn new(factory: F) -> Self { pub fn new(factory: F) -> Self {

View File

@ -443,7 +443,10 @@ impl<B> From<ServiceResponse<B>> for Response<B> {
} }
} }
impl<B: MessageBody> fmt::Debug for ServiceResponse<B> { impl<B> fmt::Debug for ServiceResponse<B>
where
B: MessageBody<Error = Error>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let res = writeln!( let res = writeln!(
f, f,

View File

@ -150,7 +150,7 @@ where
pub async fn read_response<S, B>(app: &S, req: Request) -> Bytes pub async fn read_response<S, B>(app: &S, req: Request) -> Bytes
where where
S: Service<Request, Response = ServiceResponse<B>, Error = Error>, S: Service<Request, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody + Unpin, B: MessageBody<Error = Error> + Unpin,
{ {
let mut resp = app let mut resp = app
.call(req) .call(req)
@ -195,7 +195,7 @@ where
/// ``` /// ```
pub async fn read_body<B>(mut res: ServiceResponse<B>) -> Bytes pub async fn read_body<B>(mut res: ServiceResponse<B>) -> Bytes
where where
B: MessageBody + Unpin, B: MessageBody<Error = Error> + Unpin,
{ {
let mut body = res.take_body(); let mut body = res.take_body();
let mut bytes = BytesMut::new(); let mut bytes = BytesMut::new();
@ -244,7 +244,7 @@ where
/// ``` /// ```
pub async fn read_body_json<T, B>(res: ServiceResponse<B>) -> T pub async fn read_body_json<T, B>(res: ServiceResponse<B>) -> T
where where
B: MessageBody + Unpin, B: MessageBody<Error = Error> + Unpin,
T: DeserializeOwned, T: DeserializeOwned,
{ {
let body = read_body(res).await; let body = read_body(res).await;
@ -305,7 +305,7 @@ where
pub async fn read_response_json<S, B, T>(app: &S, req: Request) -> T pub async fn read_response_json<S, B, T>(app: &S, req: Request) -> T
where where
S: Service<Request, Response = ServiceResponse<B>, Error = Error>, S: Service<Request, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody + Unpin, B: MessageBody<Error = Error> + Unpin,
T: DeserializeOwned, T: DeserializeOwned,
{ {
let body = read_response(app, req).await; let body = read_response(app, req).await;