HAProxy community

Use_backend with cookie / map

#1

hi,
I am routing to a backend if a certain cookie exists in the request.
The following works just fine:

acl has_cookie req.cook(lacan_xyz) -m found
use_backend canary_backend if has_cookie

Ideally I would like to use a map definition to avoid having to restart haproxy if/when the cookie name or value changes (from my understanding, making changes to map files can work without a restart). For example:

use_backend %[req.cook(lacan_xyz), map(/etc/haproxy/map_file.map, default_backend)]

In map_file.map, the key would be the cookie value and the value would be the name of a backend definition.

Attempting to do this results in a warning, and my desired functionality not working.

The warning:
Starting haproxy: [WARNING] 115/173343 (16970) : parsing [/etc/haproxy/haproxy.cfg:57] : Ignoring end of truncated ‘acl’ line after ‘req.cook(lacan_xyz),’

The haproxy version being used:
HA-Proxy version 1.6.1 2015/10/20

any insight or suggestions would be most appreciated,
thank you

#2

acl has_cookie -m found req.cook(lacan_xyz)

#3

Thanks - I appreciate the reply, but that didn’t do it.
It’s the following that I am trying to get working:
use_backend %[req.cook(lacan_xyz), map(/etc/haproxy/map_file.map, default_backend)]

#4

I wanted to point to the fact that you might have a syntax error in the acl line. I would write this as:

acl has_cookie -m found req.cook(lacan_xyz)
use_backend %[req.cook(lacan_xyz), lower, map(/etc/haproxy/map_file.map)] if has_cookie
default_backend some-backend