# Use\_backend with cookie / map

**URL:** <https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761>\
**Category:** Help!\
**Created:** [April 26, 2019, 9:36pm UTC](https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761 "2019-04-26T21:36:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bd76](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bd76](https://discourse.haproxy.org/u/bd76)\
**Post date:** [April 26, 2019, 9:36pm UTC](https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761/1 "2019-04-26T21:36:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![IgorC](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/igorc/32/161_2.png) [@IgorC](https://discourse.haproxy.org/u/IgorC)\
**Post date:** [April 28, 2019, 1:35am UTC](https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761/2 "2019-04-28T01:35:45Z")

</div>

> [@bd76](#):
>
> acl has\_cookie req.cook(lacan\_xyz) -m found

acl has\_cookie -m found req.cook(lacan\_xyz)

---

<div class="post-metadata">

**Author:** ![bd76](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bd76](https://discourse.haproxy.org/u/bd76)\
**Post date:** [April 30, 2019, 10:57am UTC](https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761/3 "2019-04-30T10:57:47Z")

</div>

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)]

---

<div class="post-metadata">

**Author:** ![IgorC](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/igorc/32/161_2.png) [@IgorC](https://discourse.haproxy.org/u/IgorC)\
**Post date:** [May 14, 2019, 11:13pm UTC](https://discourse.haproxy.org/t/use-backend-with-cookie-map/3761/4 "2019-05-14T23:13:10Z")

</div>

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

```auto
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

```
