mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
add Response::map_body
This commit is contained in:
parent
118606262b
commit
e6e83ea57e
@ -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;
|
||||||
|
@ -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> {
|
||||||
|
Loading…
Reference in New Issue
Block a user