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
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…
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:
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.
I need to do the same thing, as our webservers respond with an inappropriate JSON, which requires a fix. Unfortunately, we can’t get it right on the webservers.
The response body is quite small (e.g. 200-300 Bytes), and the URI is rarely requested.
We are using haproxy 2.1. with LUA support enabled.
I’ve read about SPOE and LUA, but have not used these yet.
At the same time, the official documentation states “HAProxy is not: a data scrubber : it will not modify the body of requests nor responses.”
Has anyone used HAProxy for a similar purpose yet? Or is it just inappropriate for this task?