Map function doesn't return default value

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.

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

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.

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

Thank you for looking at the problem!