mirror of https://github.com/fafhrd91/actix-web
inline convenience map body calls
This commit is contained in:
parent
3a183811cc
commit
1008598880
|
@ -4,8 +4,8 @@
|
|||
### Added
|
||||
* Methods on `AcceptLanguage`: `ranked` and `preference`. [#2480]
|
||||
* `AcceptEncoding` typed header. [#2482]
|
||||
* `HttpResponse::map_into_{left,right}_body`. [#2468]
|
||||
* `HttpResponse::map_into_boxed_body`. [#2468]
|
||||
* `HttpResponse::map_into_{left,right}_body` and `HttpResponse::map_into_boxed_body`. [#2468]
|
||||
* `ServiceResponse::map_into_{left,right}_body` and `HttpResponse::map_into_boxed_body`. [#2468]
|
||||
|
||||
### Changed
|
||||
* Rename `Accept::{mime_precedence => ranked}`. [#2480]
|
||||
|
|
|
@ -190,6 +190,7 @@ impl<B> Response<B> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_boxed_body(self) -> Response<BoxBody>
|
||||
where
|
||||
B: MessageBody + 'static,
|
||||
|
|
|
@ -150,7 +150,8 @@ where
|
|||
|
||||
Either::right(ok(req
|
||||
.into_response(res)
|
||||
.map_body(|_, body| EitherBody::right(BoxBody::new(body)))))
|
||||
.map_into_boxed_body()
|
||||
.map_into_right_body()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -357,7 +357,7 @@ impl HttpResponseBuilder {
|
|||
S: Stream<Item = Result<Bytes, E>> + 'static,
|
||||
E: Into<BoxError> + 'static,
|
||||
{
|
||||
self.body(BoxBody::new(BodyStream::new(stream)))
|
||||
self.body(BodyStream::new(stream))
|
||||
}
|
||||
|
||||
/// Set a JSON body and build the `HttpResponse`.
|
||||
|
@ -387,7 +387,7 @@ impl HttpResponseBuilder {
|
|||
/// `HttpResponseBuilder` can not be used after this call.
|
||||
#[inline]
|
||||
pub fn finish(&mut self) -> HttpResponse {
|
||||
self.body(BoxBody::new(()))
|
||||
self.body(())
|
||||
}
|
||||
|
||||
/// This method construct new `HttpResponseBuilder`
|
||||
|
|
|
@ -229,14 +229,17 @@ impl<B> HttpResponse<B> {
|
|||
|
||||
// TODO: docs for the body map methods below
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_left_body<R>(self) -> HttpResponse<EitherBody<B, R>> {
|
||||
self.map_body(|_, body| EitherBody::left(body))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_right_body<L>(self) -> HttpResponse<EitherBody<L, B>> {
|
||||
self.map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_boxed_body(self) -> HttpResponse<BoxBody>
|
||||
where
|
||||
B: MessageBody + 'static,
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use actix_http::{
|
||||
body::{BoxBody, MessageBody},
|
||||
body::{BoxBody, EitherBody, MessageBody},
|
||||
http::{HeaderMap, Method, StatusCode, Uri, Version},
|
||||
Extensions, HttpMessage, Payload, PayloadStream, RequestHead, Response, ResponseHead,
|
||||
};
|
||||
|
@ -410,6 +410,7 @@ impl<B> ServiceResponse<B> {
|
|||
|
||||
impl<B> ServiceResponse<B> {
|
||||
/// Set a new body
|
||||
#[inline]
|
||||
pub fn map_body<F, B2>(self, f: F) -> ServiceResponse<B2>
|
||||
where
|
||||
F: FnOnce(&mut ResponseHead, B) -> B2,
|
||||
|
@ -422,6 +423,17 @@ impl<B> ServiceResponse<B> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_left_body<R>(self) -> ServiceResponse<EitherBody<B, R>> {
|
||||
self.map_body(|_, body| EitherBody::left(body))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_right_body<L>(self) -> ServiceResponse<EitherBody<L, B>> {
|
||||
self.map_body(|_, body| EitherBody::right(body))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn map_into_boxed_body(self) -> ServiceResponse<BoxBody>
|
||||
where
|
||||
B: MessageBody + 'static,
|
||||
|
|
Loading…
Reference in New Issue