HAProxy community

Rewrite of response body

Hi all
I am hoping someone can help me, is it possible to rewrite URLs in a response body ( not response header). I have a requirement that makes an api request through the HAProxy (as an api gateway) that returns a list of URLs( amongst other items) in the response body that are used to make further api requests to backend, however I want all requests to use the HAProxy api gateway and to mask urls from users, any ideas on how to rewrite items in a response body.

Hopefully someone can give me a clue how to achieve this
Regards

Ian

To my knowledge HAProxy doesn’t support rewrites of bodies (neither for requests or responses).

I could perhaps look at the SPOE feature of HAProxy which could be abused to perhaps implement this. (I’m not sure, but it’s a good place to look.)

Alternatively you could use Lua-based services that do the request and mangle the response, however I would suspect this will have noticeable performance impact…

The best choice though, is to just return proper response body…

thanks for the response, I will look into your suggestions. Unfortunately I don’t have the power to change the response body.

Personally – if I really needed to mangle the response body – I would just write a HTTP proxy server in Go (or perhaps even in NodeJS), and just “stick” it between the client and the actual server with support of HAProxy like so:

[client] -> HAProxy -> [mangler] -> HAProxy -> [server]

I usually do so with this with Varnish. The reason to send requests from the “mangler” through HAProxy again is mainly for control and logging, and the fact that the “mangler” doesn’t now require to know the backend servers.