Skip to content
Discussion options

You must be logged in to vote

actix_web::body::to_bytes().await is made for this purpose but you should only use this in a middleware if you are confident that no responses use streaming bodies.

Since it requires ownership of the body, you'll need to "replace" the body, read it and then, put the body back later.

type Response = ServiceResponse<Bytes>;

// [snip]

let (req, res)  = res.into_parts(());
let (res, body) = res.into_parts();
let body_bytes = actix_web::body::to_bytes(body).await.ok().unwrap();
println!("{:?}", body_bytes);
let res = res.set_body(body_bytes);
let res = ServiceResponse::new(req, res);

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@danilhendrasr
Comment options

@robjtede
Comment options

@danilhendrasr
Comment options

@robjtede
Comment options

@danilhendrasr
Comment options

Answer selected by danilhendrasr
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