mirror of https://github.com/fafhrd91/actix-web
make Response::message_body fallible
This commit is contained in:
parent
62890c831b
commit
ab3452dee1
|
@ -235,25 +235,27 @@ impl ResponseBuilder {
|
||||||
/// This `ResponseBuilder` will be left in a useless state.
|
/// This `ResponseBuilder` will be left in a useless state.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn body<B: Into<Body>>(&mut self, body: B) -> Response<Body> {
|
pub fn body<B: Into<Body>>(&mut self, body: B) -> Response<Body> {
|
||||||
self.message_body(body.into())
|
match self.message_body(body.into()) {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(err) => Response::from_error(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate response with a body.
|
/// Generate response with a body.
|
||||||
///
|
///
|
||||||
/// This `ResponseBuilder` will be left in a useless state.
|
/// This `ResponseBuilder` will be left in a useless state.
|
||||||
pub fn message_body<B>(&mut self, body: B) -> Response<B> {
|
pub fn message_body<B>(&mut self, body: B) -> Result<Response<B>, Error> {
|
||||||
// TODO: put error handling back somehow
|
if let Some(err) = self.err.take() {
|
||||||
// if let Some(e) = self.err.take() {
|
return Err(err.into());
|
||||||
// return Response::from(Error::from(e)).into_body();
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
let response = self.head.take().expect("cannot reuse response builder");
|
let response = self.head.take().expect("cannot reuse response builder");
|
||||||
|
|
||||||
Response {
|
Ok(Response {
|
||||||
head: response,
|
head: response,
|
||||||
body: Some(body),
|
body: Some(body),
|
||||||
error: None,
|
error: None,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate response with a streaming body.
|
/// Generate response with a streaming body.
|
||||||
|
|
|
@ -52,7 +52,7 @@ where
|
||||||
|
|
||||||
fn call(&self, (req, mut framed): (Request, Framed<T, h1::Codec>)) -> Self::Future {
|
fn call(&self, (req, mut framed): (Request, Framed<T, h1::Codec>)) -> Self::Future {
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let res = ws::handshake(req.head()).unwrap().message_body(());
|
let res = ws::handshake(req.head()).unwrap().message_body(()).unwrap();
|
||||||
|
|
||||||
framed
|
framed
|
||||||
.send((res, body::BodySize::None).into())
|
.send((res, body::BodySize::None).into())
|
||||||
|
|
Loading…
Reference in New Issue