1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 18:44:35 +01:00

add Response::map_body

This commit is contained in:
Nikolay Kim 2019-02-18 17:01:35 -08:00
parent 118606262b
commit e6e83ea57e
2 changed files with 15 additions and 2 deletions

View File

@ -89,12 +89,11 @@ pub mod h2;
pub mod test; pub mod test;
pub mod ws; pub mod ws;
pub use self::body::{Body, MessageBody};
pub use self::config::{KeepAlive, ServiceConfig, ServiceConfigBuilder}; pub use self::config::{KeepAlive, ServiceConfig, ServiceConfigBuilder};
pub use self::error::{Error, ResponseError, Result}; pub use self::error::{Error, ResponseError, Result};
pub use self::extensions::Extensions; pub use self::extensions::Extensions;
pub use self::httpmessage::HttpMessage; pub use self::httpmessage::HttpMessage;
pub use self::message::{Message, RequestHead, ResponseHead}; pub use self::message::{Head, Message, RequestHead, ResponseHead};
pub use self::payload::{Payload, PayloadStream}; pub use self::payload::{Payload, PayloadStream};
pub use self::request::Request; pub use self::request::Request;
pub use self::response::Response; pub use self::response::Response;

View File

@ -242,6 +242,20 @@ impl<B: MessageBody> Response<B> {
self.body, self.body,
) )
} }
/// Set a body and return previous body value
pub fn map_body<F, B2: MessageBody>(mut self, f: F) -> Response<B2>
where
F: FnOnce(&mut ResponseHead, ResponseBody<B>) -> ResponseBody<B2>,
{
let body = f(&mut self.head, self.body);
Response {
head: self.head,
body: body,
error: self.error,
}
}
} }
impl<B: MessageBody> fmt::Debug for Response<B> { impl<B: MessageBody> fmt::Debug for Response<B> {