Request Body Modification
I am working on a reverse proxy for a particular purpose and need to modify/replace the request body during processing. In OpenResty, I used set_body_data to replace the body of a request before passing it to the destination.
I am looking for a similar functionality in Pingora. Is this available today? Any idea of how can I achieve it?
Not available today but very soon, likely our next weekly sync.
It would be great to have such a method!!! I'm trying to archive the same thing. Looking forward to it...
request_body_filter with the ability to mutate body added in f38f3b9a38cae13e116f868ef23e977252dc24a2. Feel free to open issues if that API doesn't meet your needs.
I'm trying to mutate the body, but seems that upstream is still getting the old content-length and so failing the request later in the
https://github.com/cloudflare/pingora/blob/main/pingora-core/src/protocols/http/v1/body.rs#L594
Of course i tried to se the new one in the request_body_filter but still the same.
Is there a right way to set the content length that i am missing?
[2024-07-01T09:50:36Z ERROR pingora_proxy] Fail to proxy: Upstream PrematureBodyEnd context: Peer: addr: YOLO, scheme: HTTPS,sni: YOLO, cause: context: Content-length: 276 bytes written: 266, status: 502, tries: 1, retry: false, POST YOLO, Host: 127.0.0.1:6191
You have to have to either know the content-length ahead of time and manually update it or erase the content-length header and use chunked encoding instead. Because the content-length in HTTP header is sent before the body is received and modified, there is no way the system can automatically take care of the content length calculation for the user.
For update the request header, can we also do that in request_body_filter? or we have to do it in upstream_request_filter?
If it is latter, It seems like upstream_request_filter is executed before request_body_filter. So, we cannot know what the new length of the request body is.