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:
parent
2fffc55d34
commit
b5b9f9656e
17
src/error.rs
17
src/error.rs
@ -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(),
|
||||
}
|
||||
}
|
||||
|
@ -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>,
|
||||
|
Loading…
Reference in New Issue
Block a user