mirror of https://github.com/fafhrd91/actix-web
simplify into body calls
This commit is contained in:
parent
c3c59e40d1
commit
56bdb39215
|
@ -105,12 +105,8 @@ where
|
|||
|
||||
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
|
||||
match self {
|
||||
Some(val) => val
|
||||
.respond_to(req)
|
||||
.map_body(|_, body| EitherBody::left(body)),
|
||||
|
||||
None => HttpResponse::new(StatusCode::NOT_FOUND)
|
||||
.map_body(|_, body| EitherBody::right(body)),
|
||||
Some(val) => val.respond_to(req).map_into_left_body(),
|
||||
None => HttpResponse::new(StatusCode::NOT_FOUND).map_into_right_body(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,13 +121,8 @@ where
|
|||
|
||||
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
|
||||
match self {
|
||||
Ok(val) => val
|
||||
.respond_to(req)
|
||||
.map_body(|_, body| EitherBody::left(body)),
|
||||
|
||||
Err(err) => {
|
||||
HttpResponse::from_error(err.into()).map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
Ok(val) => val.respond_to(req).map_into_left_body(),
|
||||
Err(err) => HttpResponse::from_error(err.into()).map_into_right_body(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +269,7 @@ where
|
|||
res.headers_mut().insert(k, v);
|
||||
}
|
||||
|
||||
res.map_body(|_, body| EitherBody::left(body))
|
||||
res.map_into_left_body()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,13 +152,8 @@ where
|
|||
|
||||
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
|
||||
match self {
|
||||
Either::Left(a) => a
|
||||
.respond_to(req)
|
||||
.map_body(|_, body| body::EitherBody::left(body)),
|
||||
|
||||
Either::Right(b) => b
|
||||
.respond_to(req)
|
||||
.map_body(|_, body| body::EitherBody::right(body)),
|
||||
Either::Left(a) => a.respond_to(req).map_into_left_body(),
|
||||
Either::Right(b) => b.respond_to(req).map_into_right_body(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,14 +189,13 @@ impl<T: Serialize> Responder for Form<T> {
|
|||
.content_type(mime::APPLICATION_WWW_FORM_URLENCODED)
|
||||
.message_body(body)
|
||||
{
|
||||
Ok(res) => res.map_body(|_, body| EitherBody::left(body)),
|
||||
Err(err) => {
|
||||
HttpResponse::from_error(err).map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
Ok(res) => res.map_into_left_body(),
|
||||
Err(err) => HttpResponse::from_error(err).map_into_right_body(),
|
||||
},
|
||||
|
||||
Err(err) => HttpResponse::from_error(UrlencodedError::Serialize(err))
|
||||
.map_body(|_, body| EitherBody::right(body)),
|
||||
Err(err) => {
|
||||
HttpResponse::from_error(UrlencodedError::Serialize(err)).map_into_right_body()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,14 +125,13 @@ impl<T: Serialize> Responder for Json<T> {
|
|||
.content_type(mime::APPLICATION_JSON)
|
||||
.message_body(body)
|
||||
{
|
||||
Ok(res) => res.map_body(|_, body| EitherBody::left(body)),
|
||||
Err(err) => {
|
||||
HttpResponse::from_error(err).map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
Ok(res) => res.map_into_left_body(),
|
||||
Err(err) => HttpResponse::from_error(err).map_into_right_body(),
|
||||
},
|
||||
|
||||
Err(err) => HttpResponse::from_error(JsonPayloadError::Serialize(err))
|
||||
.map_body(|_, body| EitherBody::right(body)),
|
||||
Err(err) => {
|
||||
HttpResponse::from_error(JsonPayloadError::Serialize(err)).map_into_right_body()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue