HAProxy community

How to convert boolean to string

I would like to log if the response is compressed by haproxy or not

this is an example config:

 http-response set-var(txn.comp) yes if { res.comp }    
 http-response set-var(txn.comp) no unless { res.comp }    

log-format compress\ %[txn.comp] 

of course it’s not working.

How can do that?

you must use a sample fetch after http-response set-var, use the following

http-response set-var(txn.comp) str(yes) if { res.comp }
http-response set-var(txn.comp) str(no) unless { res.comp }

https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#http-response%20set-var

you get the content of the variable with var(txn.comp) so write your log-format line like this:
log-format compress\ %[var(txn.comp)]

https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#var

1 Like

thank you so much, it works