I've been using TS+Lua for a number of years now. I've got Lua doing the remap function, so that I can use ts.client_request.set_url_host() to map the original HTTP hostname to a central DNS domain that I manage. Servers are all Ubuntu Bionic running the stock Bionic 7.1.2+ds-3.


Given "Host: myhostname.com", I do a ts.client_request.set_url_host with "myhostname.com.anotherdomain.com" (where anotherdomain.com is the centrally-managed domain). It gives me the ability to set the Origin DNS without mucking with the original domains. Works great.

I'd like to set a fallback in case the DNS lookup for 'myhostname.com.anotherhostname.com' fails. It's not ideal, but it's for an temporary internal migration and I want to make sure I don't break any domains' traffic if there's no DNS record for "myhostname.com.anotherdomain.com". Essentially I'd like to be able to set a catchall in case of a DNS failure.

What I'm looking for is some way to set that fallback (either via setting an explicit Origin IP or a hostname that'd be re-resolved), if the original DNS lookup fails.


client -> TS -> remap myhostname.com to myhostname.com.anotherhostname.com ---> 
DNS lookup succeeds? -> continue normally
DNS lookup fails? -> set_url_host() with fallback IP/hostname

I've got a hook attached to TS_LUA_HOOK_OS_DNS but it only seems to fire if the DNS lookup succeeds. TS_LUA_HOOK_POST_REMAP seems to also fire *before* TS_LUA_HOOK_OS_DNS (or at least ts.server_request.server_addr.get_addr() returns '::' inside TS_LUA_HOOK_POST_REMAP), so that's no help. 

Is there any way I can call ts.client_request.set_url_host() *again* with a fallback IP/host?

Or alternatively, set something like ts.ctx[ 'failed-dns' ] and restart the request in TS?