Closed wyanlord closed 4 years ago
check out
might have some methods you can use for accessing the req/res body
If I take the req body from service request stream, how do I put the body buffer into the service request again.
Because the request body needs to be parsed into json later again.
And the function call
of middleware is not async, so I can not execute the await of the stream at the function call
.
Do I say more detail?
@wyanlord If I am understanding correctly I am currently doing something similar. I am doing HMAC verification, thus I needed the request body as well. Since I needed to put the body back into the request after inspecting it here is a snippet of the code I am using in the call() function, simplified a bit:
Box::pin(async move {
let body_result: Result<BytesMut, Error> = get_request_body(&mut req).await;
match body_result {
Ok(bytes) => {
// get the payload body for further use
let req_body = String::from_utf8(bytes.to_vec());
// put the payload back into the ServiceRequest
let mut payload = actix_http::h1::Payload::empty();
payload.unread_data(bytes.freeze());
req.set_payload(payload.into());
match req_body {...}
}
Err(e) => ...
}
})
Not saying this is the best way to do it, but this is what I had to do to get it to work for me. If anyone else has any suggestions or critiques I would love to hear them.
I cannot view RequestBody and ResponseBody in the log middleware. These are business logs, which are necessary for troubleshooting the submission and return of data.