HAProxy community

Map function doesn't return default value

#1

I have following HAProxy configuration on 1.8.14

http-request set-var(txn.a) hdr(Origin)
acl x var(txn.a),lower,map(/etc/haproxy/test.map,'false') -m found
http-response    add-header  B  %[var(txn.a)]   if x

I expected the behavior to be that if a request’s Origin header content is present in test.map file, the response will have a new header B with that content. However I’m getting header B set with Origin’s content despite if the content is in test.map or not. What did I do wrong? Thanks for the help in advance.

0 Likes

#2

Are you getting header B set with the original content or with the value 'false', because the latter is what you configured?

0 Likes

#3

I’m getting the content I wanted(the content from request’s Origin header). It’s just getting set all the time instead of only getting set when the content is in the map file.

0 Likes

#4

After some experiment, this worked for me.

http-request set-var(txn.a) hdr(Origin)
acl x var(txn.a),lower,map_end(/etc/haproxy/test.map) -m found
http-response    add-header  B  %[var(txn.a)]   if x
1 Like

#5

Thank you for looking at the problem!

0 Likes