cloudflare / pingora

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

Request Body Modification #243

Closed Bukati closed 1 month ago

Bukati commented 1 month ago

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?

andrewhavck commented 1 month ago

Not available today but very soon, likely our next weekly sync.

iluxav commented 1 month ago

It would be great to have such a method!!! I'm trying to archive the same thing. Looking forward to it...

drcaramelsyrup commented 1 month ago

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.

N3mes1s commented 18 hours ago

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