1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

do not allow stream or actor responses for internal error #301

This commit is contained in:
Nikolay Kim 2018-06-11 19:44:11 -07:00
parent 2fffc55d34
commit b5b9f9656e
2 changed files with 16 additions and 3 deletions

View File

@ -3,7 +3,7 @@ use std::io::Error as IoError;
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use std::sync::Mutex;
use std::{fmt, io, result};
use std::{fmt, io, mem, result};
use actix::MailboxError;
use cookie;
@ -21,6 +21,7 @@ pub use url::ParseError as UrlParseError;
// re-exports
pub use cookie::ParseError as CookieParseError;
use body::Body;
use handler::Responder;
use httprequest::HttpRequest;
use httpresponse::{HttpResponse, InnerHttpResponse};
@ -652,9 +653,21 @@ impl<T> InternalError<T> {
/// Create `InternalError` with predefined `HttpResponse`.
pub fn from_response(cause: T, response: HttpResponse) -> Self {
let mut resp = response.into_inner();
let body = mem::replace(&mut resp.body, Body::Empty);
match body {
Body::Empty => (),
Body::Binary(mut bin) => {
resp.body = Body::Binary(bin.take().into());
}
Body::Streaming(_) | Body::Actor(_) => {
error!("Streaming or Actor body is not support by error response");
}
}
InternalError {
cause,
status: InternalErrorType::Response(Mutex::new(Some(response.into_inner()))),
status: InternalErrorType::Response(Mutex::new(Some(resp))),
backtrace: Backtrace::new(),
}
}

View File

@ -797,7 +797,7 @@ pub(crate) struct InnerHttpResponse {
headers: HeaderMap,
status: StatusCode,
reason: Option<&'static str>,
body: Body,
pub(crate) body: Body,
chunked: Option<bool>,
encoding: Option<ContentEncoding>,
connection_type: Option<ConnectionType>,