mirror of https://github.com/fafhrd91/actix-web
fix doc tests
This commit is contained in:
parent
274a3a9c07
commit
62890c831b
|
@ -464,9 +464,8 @@ impl ResponseError for ContentTypeError {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use std::io;
|
/// # use std::io;
|
||||||
/// # use actix_http::*;
|
/// # use actix_http::{error, Request};
|
||||||
///
|
/// fn index(req: Request) -> Result<&'static str, actix_http::Error> {
|
||||||
/// fn index(req: Request) -> Result<&'static str> {
|
|
||||||
/// Err(error::ErrorBadRequest(io::Error::new(io::ErrorKind::Other, "error")))
|
/// Err(error::ErrorBadRequest(io::Error::new(io::ErrorKind::Other, "error")))
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -320,7 +320,7 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_response_any_body(
|
fn send_error_response(
|
||||||
self: Pin<&mut Self>,
|
self: Pin<&mut Self>,
|
||||||
message: Response<()>,
|
message: Response<()>,
|
||||||
body: Body,
|
body: Body,
|
||||||
|
@ -380,7 +380,7 @@ where
|
||||||
// send_response would update InnerDispatcher state to SendPayload or
|
// send_response would update InnerDispatcher state to SendPayload or
|
||||||
// None(If response body is empty).
|
// None(If response body is empty).
|
||||||
// continue loop to poll it.
|
// 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.
|
// return with upgrade request and poll it exclusively.
|
||||||
|
@ -402,7 +402,7 @@ where
|
||||||
Poll::Ready(Err(err)) => {
|
Poll::Ready(Err(err)) => {
|
||||||
let res = Response::from_error(err.into());
|
let res = Response::from_error(err.into());
|
||||||
let (res, body) = res.replace_body(());
|
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.
|
// service call pending and could be waiting for more chunk messages.
|
||||||
|
@ -474,7 +474,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Ready(Some(Err(err))) => {
|
Poll::Ready(Some(Err(err))) => {
|
||||||
return Err(DispatchError::Service(err))
|
return Err(DispatchError::Service(err.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
Poll::Pending => return Ok(PollResponse::DoNothing),
|
Poll::Pending => return Ok(PollResponse::DoNothing),
|
||||||
|
@ -499,7 +499,7 @@ where
|
||||||
Poll::Ready(Err(err)) => {
|
Poll::Ready(Err(err)) => {
|
||||||
let res = Response::from_error(err.into());
|
let res = Response::from_error(err.into());
|
||||||
let (res, body) = res.replace_body(());
|
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.
|
// expect must be solved before progress can be made.
|
||||||
|
@ -549,7 +549,7 @@ where
|
||||||
Poll::Ready(Err(err)) => {
|
Poll::Ready(Err(err)) => {
|
||||||
let res = Response::from_error(err.into());
|
let res = Response::from_error(err.into());
|
||||||
let (res, body) = res.replace_body(());
|
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)) => {
|
Poll::Ready(Err(err)) => {
|
||||||
let res = Response::from_error(err.into());
|
let res = Response::from_error(err.into());
|
||||||
let (res, body) = res.replace_body(());
|
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
|
// Requests overflow buffer size should be responded with 431
|
||||||
this.messages.push_back(DispatcherMessage::Error(
|
this.messages.push_back(DispatcherMessage::Error(
|
||||||
Response::new(StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE)
|
Response::with_body(
|
||||||
.drop_body(),
|
StatusCode::REQUEST_HEADER_FIELDS_TOO_LARGE,
|
||||||
|
(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
this.flags.insert(Flags::READ_DISCONNECT);
|
this.flags.insert(Flags::READ_DISCONNECT);
|
||||||
*this.error = Some(ParseError::TooLarge.into());
|
*this.error = Some(ParseError::TooLarge.into());
|
||||||
|
@ -769,9 +771,8 @@ where
|
||||||
} else {
|
} else {
|
||||||
// timeout on first request (slow request) return 408
|
// timeout on first request (slow request) return 408
|
||||||
trace!("Slow request timeout");
|
trace!("Slow request timeout");
|
||||||
let _ = self.as_mut().send_response_any_body(
|
let _ = self.as_mut().send_error_response(
|
||||||
Response::new(StatusCode::REQUEST_TIMEOUT)
|
Response::with_body(StatusCode::REQUEST_TIMEOUT, ()),
|
||||||
.drop_body(),
|
|
||||||
Body::Empty,
|
Body::Empty,
|
||||||
);
|
);
|
||||||
this = self.project();
|
this = self.project();
|
||||||
|
|
|
@ -630,7 +630,7 @@ mod tests {
|
||||||
async fn test_no_content_length() {
|
async fn test_no_content_length() {
|
||||||
let mut bytes = BytesMut::with_capacity(2048);
|
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(DATE, HeaderValue::from_static(""));
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
.insert(CONTENT_LENGTH, HeaderValue::from_static("0"));
|
.insert(CONTENT_LENGTH, HeaderValue::from_static("0"));
|
||||||
|
|
|
@ -219,11 +219,6 @@ impl<B> Response<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /// Extract response body
|
|
||||||
// pub fn take_body(&mut self) -> ResponseBody<B> {
|
|
||||||
// self.body.take_body()
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// Extract response body
|
/// Extract response body
|
||||||
pub fn into_body(self) -> B {
|
pub fn into_body(self) -> B {
|
||||||
self.body.unwrap()
|
self.body.unwrap()
|
||||||
|
|
|
@ -38,7 +38,7 @@ use crate::{
|
||||||
/// .body("1234");
|
/// .body("1234");
|
||||||
///
|
///
|
||||||
/// assert_eq!(res.status(), StatusCode::OK);
|
/// 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!(res.headers().contains_key("server"));
|
||||||
/// assert_eq!(res.headers().get_all("set-cookie").count(), 2);
|
/// assert_eq!(res.headers().get_all("set-cookie").count(), 2);
|
||||||
|
|
Loading…
Reference in New Issue