diff --git a/actix-http/src/h1/encoder.rs b/actix-http/src/h1/encoder.rs index bd0de75b..5fcb2f68 100644 --- a/actix-http/src/h1/encoder.rs +++ b/actix-http/src/h1/encoder.rs @@ -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(); diff --git a/actix-http/src/payload.rs b/actix-http/src/payload.rs index c9f338c7..aed24e96 100644 --- a/actix-http/src/payload.rs +++ b/actix-http/src/payload.rs @@ -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 { diff --git a/actix-http/src/responses/response.rs b/actix-http/src/responses/response.rs index 6efc3c5f..da5503c1 100644 --- a/actix-http/src/responses/response.rs +++ b/actix-http/src/responses/response.rs @@ -185,7 +185,7 @@ impl Response { 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 Response { } } + /// Map the current body to a type-erased `BoxBody`. #[inline] pub fn map_into_boxed_body(self) -> Response where @@ -210,7 +211,7 @@ impl Response { 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 diff --git a/awc/src/client/mod.rs b/awc/src/client/mod.rs index 443bf123..e898d2d0 100644 --- a/awc/src/client/mod.rs +++ b/awc/src/client/mod.rs @@ -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 } diff --git a/awc/src/middleware/redirect.rs b/awc/src/middleware/redirect.rs index 704d2d79..ac669047 100644 --- a/awc/src/middleware/redirect.rs +++ b/awc/src/middleware/redirect.rs @@ -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 }; diff --git a/src/app_service.rs b/src/app_service.rs index b7c016e8..edfb3e4a 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -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(), }) } diff --git a/src/error/error.rs b/src/error/error.rs index be17c196..8450bed3 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -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, } diff --git a/src/response/response.rs b/src/response/response.rs index 33f0a54a..6a326fa6 100644 --- a/src/response/response.rs +++ b/src/response/response.rs @@ -256,7 +256,7 @@ impl HttpResponse { } } - /// 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(self, f: F) -> HttpResponse @@ -269,18 +269,23 @@ impl HttpResponse { } } - // 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(self) -> HttpResponse> { 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(self) -> HttpResponse> { 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 where @@ -289,7 +294,7 @@ impl HttpResponse { 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() }