mirror of
https://github.com/actix/actix-extras.git
synced 2024-12-01 02:44:37 +01:00
do not allow stream or actor responses for internal error #301
This commit is contained in:
parent
a0344eebeb
commit
9b012b3304
17
src/error.rs
17
src/error.rs
@ -3,7 +3,7 @@ use std::io::Error as IoError;
|
|||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::{fmt, io, result};
|
use std::{fmt, io, mem, result};
|
||||||
|
|
||||||
use actix::MailboxError;
|
use actix::MailboxError;
|
||||||
use cookie;
|
use cookie;
|
||||||
@ -22,6 +22,7 @@ pub use url::ParseError as UrlParseError;
|
|||||||
// re-exports
|
// re-exports
|
||||||
pub use cookie::ParseError as CookieParseError;
|
pub use cookie::ParseError as CookieParseError;
|
||||||
|
|
||||||
|
use body::Body;
|
||||||
use handler::Responder;
|
use handler::Responder;
|
||||||
use httprequest::HttpRequest;
|
use httprequest::HttpRequest;
|
||||||
use httpresponse::{HttpResponse, InnerHttpResponse};
|
use httpresponse::{HttpResponse, InnerHttpResponse};
|
||||||
@ -673,9 +674,21 @@ impl<T> InternalError<T> {
|
|||||||
|
|
||||||
/// Create `InternalError` with predefined `HttpResponse`.
|
/// Create `InternalError` with predefined `HttpResponse`.
|
||||||
pub fn from_response(cause: T, response: HttpResponse) -> Self {
|
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 {
|
InternalError {
|
||||||
cause,
|
cause,
|
||||||
status: InternalErrorType::Response(Mutex::new(Some(response.into_inner()))),
|
status: InternalErrorType::Response(Mutex::new(Some(resp))),
|
||||||
backtrace: Backtrace::new(),
|
backtrace: Backtrace::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,7 +810,7 @@ pub(crate) struct InnerHttpResponse {
|
|||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
status: StatusCode,
|
status: StatusCode,
|
||||||
reason: Option<&'static str>,
|
reason: Option<&'static str>,
|
||||||
body: Body,
|
pub(crate) body: Body,
|
||||||
chunked: Option<bool>,
|
chunked: Option<bool>,
|
||||||
encoding: Option<ContentEncoding>,
|
encoding: Option<ContentEncoding>,
|
||||||
connection_type: Option<ConnectionType>,
|
connection_type: Option<ConnectionType>,
|
||||||
|
Loading…
Reference in New Issue
Block a user