Hello,
First of all, thank you all for reading this post.
I’m looking for a simple method to just get the length of a string, and I supposed that there should be a converter to do this but I can’t find anything. This surprised me because there is a lot of advanced features that can be acomplished with the converters and this is a simple feature, so maybe I’m missing something?
Just to give you context and maybe this could help someone, I was looking for a way to make easier our current deployment of a proxypass with HAProxy, so my best aproach right now is this:
frontend ft-http-proxypass
bind :80
http-request set-var(req.proxypass_be) path,field(2,'/'),map(/etc/haproxy/backends.map) # Stores into a variable the backend that is going to use
acl is_proxypass var(req.proxypass_be) -m found # Just checks that the requested path is included in the mapfile
reqrep ^([^\ :]*\ \/)[^\/\ ]+\/?(.*) \1\2 if is_proxypass # Replaces the first path for a '/'. For example:
# /path1 -> /
# /path1/ -> /
# /path1/subpath -> /subpath
use_backend %[var(req.proxypass_be)] if is_proxypass
backend bk-http-site1
server server1 192.168.1.1:80
backend bk-http-site2
server server1 192.168.1.1:8080
backend bk-http-site3
server server1 192.168.1.1:8081
Just to complete the example, this could be the content of the map file:
path1 bk-http-site1
path2 bk-http-site2
path3 bk-http-site3
I’m almost happy with it, but I would like to replace the reqrep line with a ‘http-request set-path’ in conjunction with the converter ‘bytes’ (could be used like a substring function) and using the lenght of the first subpath as an offset of this bytes converter.
Is it any way to do this with the tools provided by HAProxy or is it needed to use an external tool like a lua script?
I’m using haproxy 1.8.8 btw.
Thank you!