cloudflare / pingora

A library for building fast, reliable and evolvable network services.
Apache License 2.0
20.28k stars 1.1k forks source link

Get the request body without consuming it before sending to upstream #191

Closed pengye91 closed 1 month ago

pengye91 commented 2 months ago

What is the problem your feature solves, or the need it fulfills?

currently we can't get the request body in any methods without consuming it.

we can use read_request_body() method on the session but it will consume the body causing the upstream get a None for the request body, which is not we wanted.

I think this is a common case for a proxy, for example, to log the request body.

Describe the solution you'd like

I'd like to get the request body in the request_filter or upstream_request_filter phase without consuming it.

drcaramelsyrup commented 2 months ago

I imagine we should have a request_body_filter like response_body_filter to be able to handle this.

christianscano commented 1 month ago

Nowadays, is there a momentary solution to read the request body without consuming it?

drcaramelsyrup commented 1 month ago

Note that request_body_filter was added in f38f3b9a38cae13e116f868ef23e977252dc24a2 which should allow inspecting (or mutating) the body just before sending it to the upstream.

This should fit your mentioned use case of logging the request body, so I will close, but feel free to reopen or open a new issue if you have another use case in mind. Thanks!