mirror of https://github.com/fafhrd91/actix-web
message body error type downstream
This commit is contained in:
parent
b613c64abf
commit
2b818be18f
|
@ -85,7 +85,7 @@ where
|
|||
S::InitError: fmt::Debug,
|
||||
S::Response: Into<Response<B>> + 'static,
|
||||
<S::Service as Service<Request>>::Future: 'static,
|
||||
B: MessageBody + 'static,
|
||||
B: MessageBody<Error = Error> + 'static,
|
||||
{
|
||||
start_with(TestServerConfig::default(), factory)
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ where
|
|||
S::InitError: fmt::Debug,
|
||||
S::Response: Into<Response<B>> + 'static,
|
||||
<S::Service as Service<Request>>::Future: 'static,
|
||||
B: MessageBody + 'static,
|
||||
B: MessageBody<Error = Error> + 'static,
|
||||
{
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
|
|
|
@ -113,7 +113,9 @@ pub trait MapServiceResponseBody {
|
|||
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 {
|
||||
self.map_body(|_, body| ResponseBody::Other(Body::from_message(body)))
|
||||
}
|
||||
|
|
|
@ -22,10 +22,9 @@ use time::OffsetDateTime;
|
|||
|
||||
use crate::{
|
||||
dev::{BodySize, MessageBody, ResponseBody},
|
||||
error::{Error, Result},
|
||||
http::{HeaderName, StatusCode},
|
||||
service::{ServiceRequest, ServiceResponse},
|
||||
HttpResponse,
|
||||
Error, HttpResponse, Result,
|
||||
};
|
||||
|
||||
/// 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 {
|
||||
self.body.size()
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
f.debug_struct("HttpResponse")
|
||||
.field("error", &self.error)
|
||||
|
|
|
@ -80,7 +80,7 @@ where
|
|||
<S::Service as Service<Request>>::Future: 'static,
|
||||
S::Service: 'static,
|
||||
// S::Service: 'static,
|
||||
B: MessageBody + 'static,
|
||||
B: MessageBody<Error = Error> + 'static,
|
||||
{
|
||||
/// Create new HTTP server with application factory
|
||||
pub fn new(factory: F) -> Self {
|
||||
|
|
|
@ -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 {
|
||||
let res = writeln!(
|
||||
f,
|
||||
|
|
|
@ -150,7 +150,7 @@ where
|
|||
pub async fn read_response<S, B>(app: &S, req: Request) -> Bytes
|
||||
where
|
||||
S: Service<Request, Response = ServiceResponse<B>, Error = Error>,
|
||||
B: MessageBody + Unpin,
|
||||
B: MessageBody<Error = Error> + Unpin,
|
||||
{
|
||||
let mut resp = app
|
||||
.call(req)
|
||||
|
@ -195,7 +195,7 @@ where
|
|||
/// ```
|
||||
pub async fn read_body<B>(mut res: ServiceResponse<B>) -> Bytes
|
||||
where
|
||||
B: MessageBody + Unpin,
|
||||
B: MessageBody<Error = Error> + Unpin,
|
||||
{
|
||||
let mut body = res.take_body();
|
||||
let mut bytes = BytesMut::new();
|
||||
|
@ -244,7 +244,7 @@ where
|
|||
/// ```
|
||||
pub async fn read_body_json<T, B>(res: ServiceResponse<B>) -> T
|
||||
where
|
||||
B: MessageBody + Unpin,
|
||||
B: MessageBody<Error = Error> + Unpin,
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
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
|
||||
where
|
||||
S: Service<Request, Response = ServiceResponse<B>, Error = Error>,
|
||||
B: MessageBody + Unpin,
|
||||
B: MessageBody<Error = Error> + Unpin,
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let body = read_response(app, req).await;
|
||||
|
|
Loading…
Reference in New Issue