mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
document new body map types
This commit is contained in:
parent
008753f07a
commit
50894e392e
@ -152,7 +152,6 @@ pub(crate) trait MessageType: Sized {
|
||||
let k = key.as_str().as_bytes();
|
||||
let k_len = k.len();
|
||||
|
||||
// TODO: drain?
|
||||
for val in value.iter() {
|
||||
let v = val.as_ref();
|
||||
let v_len = v.len();
|
||||
|
@ -6,6 +6,7 @@ use std::{
|
||||
|
||||
use bytes::Bytes;
|
||||
use futures_core::Stream;
|
||||
use pin_project_lite::pin_project;
|
||||
|
||||
use crate::error::PayloadError;
|
||||
|
||||
@ -15,7 +16,7 @@ pub type BoxedPayloadStream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadErr
|
||||
#[deprecated(since = "4.0.0", note = "Renamed to `BoxedPayloadStream`.")]
|
||||
pub type PayloadStream = BoxedPayloadStream;
|
||||
|
||||
pin_project_lite::pin_project! {
|
||||
pin_project! {
|
||||
/// A streaming payload.
|
||||
#[project = PayloadProj]
|
||||
pub enum Payload<S = BoxedPayloadStream> {
|
||||
|
@ -185,7 +185,7 @@ impl<B> Response<B> {
|
||||
self.replace_body(())
|
||||
}
|
||||
|
||||
/// Map the current body type to another using a closure. Returns a new response.
|
||||
/// Map the current body type to another using a closure, returning a new response.
|
||||
///
|
||||
/// Closure receives the response head and the current body type.
|
||||
#[inline]
|
||||
@ -202,6 +202,7 @@ impl<B> Response<B> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Map the current body to a type-erased `BoxBody`.
|
||||
#[inline]
|
||||
pub fn map_into_boxed_body(self) -> Response<BoxBody>
|
||||
where
|
||||
@ -210,7 +211,7 @@ impl<B> Response<B> {
|
||||
self.map_body(|_, body| body.boxed())
|
||||
}
|
||||
|
||||
/// Returns body, consuming this response.
|
||||
/// Returns the response body, dropping all other parts.
|
||||
#[inline]
|
||||
pub fn into_body(self) -> B {
|
||||
self.body
|
||||
|
@ -94,10 +94,9 @@ impl Client {
|
||||
let mut req = ClientRequest::new(method, url, self.0.clone());
|
||||
|
||||
for header in self.0.default_headers.iter() {
|
||||
// header map is empty
|
||||
// TODO: probably append instead
|
||||
req = req.insert_header_if_none(header);
|
||||
req = req.append_header(header);
|
||||
}
|
||||
|
||||
req
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ where
|
||||
| StatusCode::PERMANENT_REDIRECT
|
||||
if *max_redirect_times > 0 =>
|
||||
{
|
||||
let is_redirect = res.head().status == StatusCode::TEMPORARY_REDIRECT
|
||||
let reuse_body = res.head().status == StatusCode::TEMPORARY_REDIRECT
|
||||
|| res.head().status == StatusCode::PERMANENT_REDIRECT;
|
||||
|
||||
let prev_uri = uri.take().unwrap();
|
||||
@ -176,7 +176,7 @@ where
|
||||
let connector = connector.take();
|
||||
|
||||
// reset method
|
||||
let method = if is_redirect {
|
||||
let method = if reuse_body {
|
||||
method.take().unwrap()
|
||||
} else {
|
||||
let method = method.take().unwrap();
|
||||
@ -187,18 +187,19 @@ where
|
||||
};
|
||||
|
||||
let mut body = body.take();
|
||||
let body_new = if is_redirect {
|
||||
// try to reuse body
|
||||
let body_new = if reuse_body {
|
||||
// try to reuse saved body
|
||||
match body {
|
||||
Some(ref bytes) => AnyBody::Bytes {
|
||||
body: bytes.clone(),
|
||||
},
|
||||
// TODO: should this be AnyBody::Empty or AnyBody::None.
|
||||
|
||||
// body was a non-reusable type so send an empty body instead
|
||||
_ => AnyBody::empty(),
|
||||
}
|
||||
} else {
|
||||
body = None;
|
||||
// remove body
|
||||
// remove body since we're downgrading to a GET
|
||||
AnyBody::None
|
||||
};
|
||||
|
||||
|
@ -169,7 +169,6 @@ impl AppInitServiceState {
|
||||
Rc::new(AppInitServiceState {
|
||||
rmap,
|
||||
config,
|
||||
// TODO: AppConfig can be used to pass user defined HttpRequestPool capacity.
|
||||
pool: HttpRequestPool::default(),
|
||||
})
|
||||
}
|
||||
|
@ -4,16 +4,14 @@ use actix_http::{body::BoxBody, Response};
|
||||
|
||||
use crate::{HttpResponse, ResponseError};
|
||||
|
||||
/// General purpose actix web error.
|
||||
/// General purpose Actix Web error.
|
||||
///
|
||||
/// An actix web error is used to carry errors from `std::error`
|
||||
/// through actix in a convenient way. It can be created through
|
||||
/// converting errors with `into()`.
|
||||
/// An Actix Web error is used to carry errors from `std::error` through actix in a convenient way.
|
||||
/// It can be created through converting errors with `into()`.
|
||||
///
|
||||
/// Whenever it is created from an external object a response error is created
|
||||
/// for it that can be used to create an HTTP response from it this means that
|
||||
/// if you have access to an actix `Error` you can always get a
|
||||
/// `ResponseError` reference from it.
|
||||
/// Whenever it is created from an external object a response error is created for it that can be
|
||||
/// used to create an HTTP response from it this means that if you have access to an actix `Error`
|
||||
/// you can always get a `ResponseError` reference from it.
|
||||
pub struct Error {
|
||||
cause: Box<dyn ResponseError>,
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ impl<B> HttpResponse<B> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Map the current body type to another using a closure. Returns a new response.
|
||||
/// Map the current body type to another using a closure, returning a new response.
|
||||
///
|
||||
/// Closure receives the response head and the current body type.
|
||||
pub fn map_body<F, B2>(self, f: F) -> HttpResponse<B2>
|
||||
@ -269,18 +269,23 @@ impl<B> HttpResponse<B> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: docs for the body map methods below
|
||||
|
||||
/// Map the current body type `B` to `EitherBody::Left(B)`.
|
||||
///
|
||||
/// Useful for middleware which can generate their own responses.
|
||||
#[inline]
|
||||
pub fn map_into_left_body<R>(self) -> HttpResponse<EitherBody<B, R>> {
|
||||
self.map_body(|_, body| EitherBody::left(body))
|
||||
}
|
||||
|
||||
/// Map the current body type `B` to `EitherBody::Right(B)`.
|
||||
///
|
||||
/// Useful for middleware which can generate their own responses.
|
||||
#[inline]
|
||||
pub fn map_into_right_body<L>(self) -> HttpResponse<EitherBody<L, B>> {
|
||||
self.map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
|
||||
/// Map the current body to a type-erased `BoxBody`.
|
||||
#[inline]
|
||||
pub fn map_into_boxed_body(self) -> HttpResponse<BoxBody>
|
||||
where
|
||||
@ -289,7 +294,7 @@ impl<B> HttpResponse<B> {
|
||||
self.map_body(|_, body| body.boxed())
|
||||
}
|
||||
|
||||
/// Extract response body
|
||||
/// Returns the response body, dropping all other parts.
|
||||
pub fn into_body(self) -> B {
|
||||
self.res.into_body()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user