diff --git a/actix-http/src/error.rs b/actix-http/src/error.rs index 80fe01537..20b2a2d75 100644 --- a/actix-http/src/error.rs +++ b/actix-http/src/error.rs @@ -464,9 +464,8 @@ impl ResponseError for ContentTypeError { /// /// ``` /// # use std::io; -/// # use actix_http::*; -/// -/// fn index(req: Request) -> Result<&'static str> { +/// # use actix_http::{error, Request}; +/// fn index(req: Request) -> Result<&'static str, actix_http::Error> { /// Err(error::ErrorBadRequest(io::Error::new(io::ErrorKind::Other, "error"))) /// } /// ``` diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 4f66a4a3b..d287d9d5e 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -320,7 +320,7 @@ where Ok(()) } - fn send_response_any_body( + fn send_error_response( self: Pin<&mut Self>, message: Response<()>, body: Body, @@ -380,7 +380,7 @@ where // send_response would update InnerDispatcher state to SendPayload or // None(If response body is empty). // continue loop to poll it. - self.as_mut().send_response_any_body(res, Body::Empty)?; + self.as_mut().send_error_response(res, Body::Empty)?; } // return with upgrade request and poll it exclusively. @@ -402,7 +402,7 @@ where Poll::Ready(Err(err)) => { let res = Response::from_error(err.into()); let (res, body) = res.replace_body(()); - self.as_mut().send_response_any_body(res, body)?; + self.as_mut().send_error_response(res, body)?; } // service call pending and could be waiting for more chunk messages. @@ -474,7 +474,7 @@ where } Poll::Ready(Some(Err(err))) => { - return Err(DispatchError::Service(err)) + return Err(DispatchError::Service(err.into())) } Poll::Pending => return Ok(PollResponse::DoNothing), @@ -499,7 +499,7 @@ where Poll::Ready(Err(err)) => { let res = Response::from_error(err.into()); let (res, body) = res.replace_body(()); - self.as_mut().send_response_any_body(res, body)?; + self.as_mut().send_error_response(res, body)?; } // expect must be solved before progress can be made. @@ -549,7 +549,7 @@ where Poll::Ready(Err(err)) => { let res = Response::from_error(err.into()); let (res, body) = res.replace_body(()); - return self.send_response_any_body(res, body); + return self.send_error_response(res, body); } } } @@ -569,7 +569,7 @@ where Poll::Ready(Err(err)) => { let res = Response::from_error(err.into()); let (res, body) = res.replace_body(()); - self.send_response_any_body(res, body) + self.send_error_response(res, body) } }; } @@ -689,8 +689,10 @@ where } // Requests overflow buffer size should be responded with 431 this.messages.push_back(DispatcherMessage::Error( - Response::new(StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE) - .drop_body(), + Response::with_body( + StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE, + (), + ), )); this.flags.insert(Flags::READ_DISCONNECT); *this.error = Some(ParseError::TooLarge.into()); @@ -769,9 +771,8 @@ where } else { // timeout on first request (slow request) return 408 trace!("Slow request timeout"); - let _ = self.as_mut().send_response_any_body( - Response::new(StatusCode::REQUEST_TIMEOUT) - .drop_body(), + let _ = self.as_mut().send_error_response( + Response::with_body(StatusCode::REQUEST_TIMEOUT, ()), Body::Empty, ); this = self.project(); diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index 65d3b0ce6..eaabcb687 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -630,7 +630,7 @@ mod tests { async fn test_no_content_length() { let mut bytes = BytesMut::with_capacity(2048); - let mut res = Response::new(StatusCode::SWITCHING_PROTOCOLS).drop_body(); + let mut res = Response::with_body(StatusCode::SWITCHING_PROTOCOLS, ()); res.headers_mut().insert(DATE, HeaderValue::from_static("")); res.headers_mut() .insert(CONTENT_LENGTH, HeaderValue::from_static("0")); diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index d9a32845f..900c4d22e 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -219,11 +219,6 @@ impl Response { } } - // /// Extract response body - // pub fn take_body(&mut self) -> ResponseBody { - // self.body.take_body() - // } - /// Extract response body pub fn into_body(self) -> B { self.body.unwrap() diff --git a/actix-http/src/response_builder.rs b/actix-http/src/response_builder.rs index 8568c23bd..32217662a 100644 --- a/actix-http/src/response_builder.rs +++ b/actix-http/src/response_builder.rs @@ -38,7 +38,7 @@ use crate::{ /// .body("1234"); /// /// assert_eq!(res.status(), StatusCode::OK); -/// assert_eq!(body::to_bytes(res.take_body()).await.unwrap(), &b"1234"[..]); +/// assert_eq!(body::to_bytes(res.into_body()).await.unwrap(), &b"1234"[..]); /// /// assert!(res.headers().contains_key("server")); /// assert_eq!(res.headers().get_all("set-cookie").count(), 2);