Skip to content

How to get the response body inside a wrap_fn middleware #3359

Answered by robjtede
Franzx41 asked this question in Q&A
Discussion options

You must be logged in to vote

The highlighted lines from this example show how to read the response body: https://github.com/actix/examples/blob/master/middleware/encrypted-payloads/src/main.rs#L127-L136

Though it's important to put a body back into the response so it actually gets sent out as well: https://github.com/actix/examples/blob/master/middleware/encrypted-payloads/src/main.rs#L153-L155

I'd also recommend using from_fn() from actix-web-lab which is a much better developer experience than wrap_fn.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by robjtede
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants