From e6e83ea57e82b59ad504420b23e2d00950756ce8 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 18 Feb 2019 17:01:35 -0800 Subject: [PATCH] add Response::map_body --- src/lib.rs | 3 +-- src/response.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4e6e37955..8750b24ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,12 +89,11 @@ pub mod h2; pub mod test; pub mod ws; -pub use self::body::{Body, MessageBody}; pub use self::config::{KeepAlive, ServiceConfig, ServiceConfigBuilder}; pub use self::error::{Error, ResponseError, Result}; pub use self::extensions::Extensions; 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::request::Request; pub use self::response::Response; diff --git a/src/response.rs b/src/response.rs index d84100fa2..0295758b2 100644 --- a/src/response.rs +++ b/src/response.rs @@ -242,6 +242,20 @@ impl Response { self.body, ) } + + /// Set a body and return previous body value + pub fn map_body(mut self, f: F) -> Response + where + F: FnOnce(&mut ResponseHead, ResponseBody) -> ResponseBody, + { + let body = f(&mut self.head, self.body); + + Response { + head: self.head, + body: body, + error: self.error, + } + } } impl fmt::Debug for Response {