Access hyper body non-destructively #2907
-
I have a middleware function that takes a In order for the downstream handlers to still have access to the body, I'm doing something like this currently: let body_bytes = hyper::body::to_bytes(req.body_mut()).await.unwrap();
// ... compute function over `body_bytes`
*req.body_mut() = body_bytes.into(); // re-insert body for downstream handlers
let mut resp = next.run(req).await; Is there a smarter way of doing this, that doesn't require the manual body re-insertion? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, what you've done works. The body from the network is streamed, it can't be replayed naturally. So the only way is to "record" it, and give that to the next layer. |
Beta Was this translation helpful? Give feedback.
No, what you've done works. The body from the network is streamed, it can't be replayed naturally. So the only way is to "record" it, and give that to the next layer.