Core concepts

Converters

On this page

A converter is a built-in function that transforms the value returned by a fetch method. For example, you could use the lower converter to make a string lowercase.

In the example below, we get the HTTP request method (e.g. GET or POST) via the method fetch and then use lower to make it lowercase. For example, GET would become get. The http-request capture directive stores this data in the access logs:

haproxy
frontend www
bind :80
http-request capture method,lower len 10
haproxy
frontend www
bind :80
http-request capture method,lower len 10

You can also chain converters one after another. In the next example, the rand fetch returns a random number between 0 and 100. We pass the result to the mul converter to multiply it by 2; Then the sub converter subtracts 5, the add converter adds 3, and the div converter divides it by 2:

haproxy
frontend www
bind :80
http-request add-header X-Random rand(1:100),mul(2),sub(5),add(3),div(2)
haproxy
frontend www
bind :80
http-request add-header X-Random rand(1:100),mul(2),sub(5),add(3),div(2)

See also Jump to heading

Do you have any suggestions on how we can improve the content of this page?