HAProxy Enterprise Documentation 1.8r2

Syntax

You use a fetch by specifying its name on a line that supports fetches, such as the acl directive. Some fetches have parameters, which are given in parentheses. Omit the parentheses for other fetches that have no parameters.

Here are a few examples of fetches that take no parameters:

# returns the client's source IP address
src

# returns the requested URL path
path

# returns the destination TCP port
dst_port

Here are a few examples of fetches that take parameters:

# returns the number of queued connections in a backend
queue(mybackend)

# returns the value of the Host HTTP header
req.hdr(Host)

# returns the value of the "abc" cookie
req.cook(abc)

Every fetch returns a value with one of the following data types:

  • Boolean

  • Integer

  • IP address

  • String

  • Binary

With this in mind, you can write conditional logic that compares the output of a fetch with a hardcoded value that aligns with the fetch's data type. For example, if a fetch returns a string, you can compare it to a hardcoded string or a regular expression, as we do here to check whether the User-Agent header matches the substring firefox:

frontend www
   bind :80

   # Does the User-Agent header contain the string 'Firefox'?
   acl is_firefox req.hdr(user-agent) -i -m sub firefox

Next up

Fetch Reference