mirror of
https://github.com/actix/actix-web.git
synced 2024-09-09 05:08:32 +00:00
add Response::map_body
This commit is contained in:
parent
118606262b
commit
e6e83ea57e
2 changed files with 15 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -242,6 +242,20 @@ impl<B: MessageBody> Response<B> {
|
|||
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> {
|
||||
|
|
Loading…
Reference in a new issue