# Custom backend according to an external script?

**URL:** <https://discourse.haproxy.org/t/custom-backend-according-to-an-external-script/3712>\
**Category:** Help!\
**Created:** [April 10, 2019, 4:44pm UTC](https://discourse.haproxy.org/t/custom-backend-according-to-an-external-script/3712 "2019-04-10T16:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylan](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dylan](https://discourse.haproxy.org/u/dylan)\
**Post date:** [April 10, 2019, 4:44pm UTC](https://discourse.haproxy.org/t/custom-backend-according-to-an-external-script/3712/1 "2019-04-10T16:44:30Z")

</div>

I’m TPROXYing to one of three backends for a custom TCP protocol; this is not HTTP.

I’m trying to figure out if there is a way to do a network call (to, for example, have haproxy call `http://10.4.2.15:8080/pass/<source IP here>` and read a response), and the response will be 1, 2, or 3. If it is 1 or 2, forward tproxy to backend1. If it is a 3, forward tproxy to different backend3. Understandably this will also slow down connects, but that’s acceptable. My backends are running cloudflare’s mmproxy to read the source IP.

I’ve read there is Lua support, but unsure if it is just for scripting basic if statements or if it’s a full lua implementation that also allows for importing libraries(?) or network access.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [April 15, 2019, 6:27pm UTC](https://discourse.haproxy.org/t/custom-backend-according-to-an-external-script/3712/2 "2019-04-15T18:27:59Z")

</div>

LUA can be used to connect to databases like redis and you also should be able to make a HTTP request, so yes, this should be possible with LUA.
