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 }


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


1 Like

thank you so much, it works