7.3. Fetching samples

  1. Historically, sample fetch methods were only used to retrieve data to match
  2. against patterns using ACLs. With the arrival of stick-tables, a new class of
  3. sample fetch methods was created, most often sharing the same syntax as their
  4. ACL counterpart. These sample fetch methods are also known as "fetches". As
  5. of now, ACLs and fetches have converged. All ACL fetch methods have been made
  6. available as fetch methods, and ACLs may use any sample fetch method as well.
  7.  
  8. This section details all available sample fetch methods and their output type.
  9. Some sample fetch methods have deprecated aliases that are used to maintain
  10. compatibility with existing configurations. They are then explicitly marked as
  11. deprecated and should not be used in new setups.
  12.  
  13. The ACL derivatives are also indicated when available, with their respective
  14. matching methods. These ones all have a well defined default pattern matching
  15. method, so it is never necessary (though allowed) to pass the "-m" option to
  16. indicate how the sample will be matched using ACLs.
  17.  
  18. As indicated in the sample type versus matching compatibility matrix above,
  19. when using a generic sample fetch method in an ACL, the "-m" option is
  20. mandatory unless the sample type is one of boolean, integer, IPv4 or IPv6. When
  21. the same keyword exists as an ACL keyword and as a standard fetch method, the
  22. ACL engine will automatically pick the ACL-only one by default.
  23.  
  24. Some of these keywords support one or multiple mandatory arguments, and one or
  25. multiple optional arguments. These arguments are strongly typed and are checked
  26. when the configuration is parsed so that there is no risk of running with an
  27. incorrect argument (e.g. an unresolved backend name). Fetch function arguments
  28. are passed between parenthesis and are delimited by commas. When an argument
  29. is optional, it will be indicated below between square brackets ('[ ]'). When
  30. all arguments are optional, the parenthesis may be omitted.
  31.  
  32. Thus, the syntax of a standard sample fetch method is one of the following :
  33. - name
  34. - name(arg1)
  35. - name(arg1,arg2)

7.3.1. Converters

  1. Sample fetch methods may be combined with transformations to be applied on top
  2. of the fetched sample (also called "converters"). These combinations form what
  3. is called "sample expressions" and the result is a "sample". Initially this
  4. was only supported by "stick on" and "stick store-request" directives but this
  5. has now be extended to all places where samples may be used (ACLs, log-format,
  6. unique-id-format, add-header, ...).
  7.  
  8. These transformations are enumerated as a series of specific keywords after the
  9. sample fetch method. These keywords may equally be appended immediately after
  10. the fetch keyword's argument, delimited by a comma. These keywords can also
  11. support some arguments (e.g. a netmask) which must be passed in parenthesis.
  12.  
  13. A certain category of converters are bitwise and arithmetic operators which
  14. support performing basic operations on integers. Some bitwise operations are
  15. supported (and, or, xor, cpl) and some arithmetic operations are supported
  16. (add, sub, mul, div, mod, neg). Some comparators are provided (odd, even, not,
  17. bool) which make it possible to report a match without having to write an ACL.
  18.  
  19. The currently available list of transformation keywords include :

51d.single([,*])

  1. Returns values for the properties requested as a string, where values are
  2. separated by the delimiter specified with "51degrees-property-separator".
  3. The device is identified using the User-Agent header passed to the
  4. converter. The function can be passed up to five property names, and if a
  5. property name can't be found, the value "NoData" is returned.

Example :

  1. # Here the header "X-51D-DeviceTypeMobileTablet" is added to the request,
  2. # containing values for the three properties requested by using the
  3. # User-Agent passed to the converter.
  4. frontend http-in
  5. bind *:8081
  6. default_backend servers
  7. http-request set-header X-51D-DeviceTypeMobileTablet \
  8. %[req.fhdr(User-Agent),51d.single(DeviceType,IsMobile,IsTablet)]

add()

  1. Adds <value> to the input value of type signed integer, and returns the
  2. result as a signed integer. <value> can be a numeric value or a variable
  3. name. The name of the variable starts with an indication about its scope. The
  4. scopes allowed are:
  5. "proc" : the variable is shared with the whole process
  6. "sess" : the variable is shared with the whole session
  7. "txn" : the variable is shared with the transaction (request and response)
  8. "req" : the variable is shared only during request processing
  9. "res" : the variable is shared only during response processing
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

aes_gcm_dec(,,,)

  1. Decrypts the raw byte input using the AES128-GCM, AES192-GCM or
  2. AES256-GCM algorithm, depending on the <bits> parameter. All other parameters
  3. need to be base64 encoded and the returned result is in raw byte format.
  4. If the <aead_tag> validation fails, the converter doesn't return any data.
  5. The <nonce>, <key> and <aead_tag> can either be strings or variables. This
  6. converter requires at least OpenSSL 1.0.1.

Example:

  1. http-response set-header X-Decrypted-Text %[var(txn.enc),\
  2. aes_gcm_dec(128,txn.nonce,Zm9vb2Zvb29mb29wZm9vbw==,txn.aead_tag)]

and()

  1. Performs a bitwise "AND" between <value> and the input value of type signed
  2. integer, and returns the result as an signed integer. <value> can be a
  3. numeric value or a variable name. The name of the variable starts with an
  4. indication about its scope. The scopes allowed are:
  5. "proc" : the variable is shared with the whole process
  6. "sess" : the variable is shared with the whole session
  7. "txn" : the variable is shared with the transaction (request and response)
  8. "req" : the variable is shared only during request processing
  9. "res" : the variable is shared only during response processing
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

b64dec

  1. Converts (decodes) a base64 encoded input string to its binary
  2. representation. It performs the inverse operation of base64().

base64

  1. Converts a binary input sample to a base64 string. It is used to log or
  2. transfer binary content in a way that can be reliably transferred (e.g.
  3. an SSL ID can be copied in a header).

bool

  1. Returns a boolean TRUE if the input value of type signed integer is
  2. non-null, otherwise returns FALSE. Used in conjunction with and(), it can be
  3. used to report true/false for bit testing on input values (e.g. verify the
  4. presence of a flag).

bytes([,])

  1. Extracts some bytes from an input binary sample. The result is a binary
  2. sample starting at an offset (in bytes) of the original sample and
  3. optionally truncated at the given length.

concat([],[],[])

  1. Concatenates up to 3 fields after the current sample which is then turned to
  2. a string. The first one, <start>, is a constant string, that will be appended
  3. immediately after the existing sample. It may be omitted if not used. The
  4. second one, <var>, is a variable name. The variable will be looked up, its
  5. contents converted to a string, and it will be appended immediately after the
  6. <first> part. If the variable is not found, nothing is appended. It may be
  7. omitted as well. The third field, <end> is a constant string that will be
  8. appended after the variable. It may also be omitted. Together, these elements
  9. allow to concatenate variables with delimiters to an existing set of
  10. variables. This can be used to build new variables made of a succession of
  11. other variables, such as colon-delimited values. Note that due to the config
  12. parser, it is not possible to use a comma nor a closing parenthesis as
  13. delimiters.

Example:

  1. tcp-request session set-var(sess.src) src
  2. tcp-request session set-var(sess.dn) ssl_c_s_dn
  3. tcp-request session set-var(txn.sig) str(),concat(<ip=,sess.ip,>),concat(<dn=,sess.dn,>)
  4. http-request set-header x-hap-sig %[var(txn.sig)]

cpl

  1. Takes the input value of type signed integer, applies a ones-complement
  2. (flips all bits) and returns the result as an signed integer.

crc32([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32
  2. hash function. Optionally, it is possible to apply a full avalanche hash
  3. function to the output if the optional <avalanche> argument equals 1. This
  4. converter uses the same functions as used by the various hash-based load
  5. balancing algorithms, so it will provide exactly the same results. It is
  6. provided for compatibility with other software which want a CRC32 to be
  7. computed on some input keys, so it follows the most common implementation as
  8. found in Ethernet, Gzip, PNG, etc... It is slower than the other algorithms
  9. but may provide a better or at least less predictable distribution. It must
  10. not be used for security purposes as a 32-bit hash is trivial to break. See
  11. also "djb2", "sdbm", "wt6", "crc32c" and the "hash-type" directive.

crc32c([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the CRC32C
  2. hash function. Optionally, it is possible to apply a full avalanche hash
  3. function to the output if the optional <avalanche> argument equals 1. This
  4. converter uses the same functions as described in RFC4960, Appendix B [8].
  5. It is provided for compatibility with other software which want a CRC32C to be
  6. computed on some input keys. It is slower than the other algorithms and it must
  7. not be used for security purposes as a 32-bit hash is trivial to break. See
  8. also "djb2", "sdbm", "wt6", "crc32" and the "hash-type" directive.

da-csv-conv([,*])

  1. Asks the DeviceAtlas converter to identify the User Agent string passed on
  2. input, and to emit a string made of the concatenation of the properties
  3. enumerated in argument, delimited by the separator defined by the global
  4. keyword "deviceatlas-property-separator", or by default the pipe character
  5. ('|'). There's a limit of 12 different properties imposed by the haproxy
  6. configuration language.

Example:

  1. frontend www
  2. bind *:8881
  3. default_backend servers
  4. http-request set-header X-DeviceAtlas-Data %[req.fhdr(User-Agent),da-csv(primaryHardwareType,osName,osVersion,browserName,browserVersion,browserRenderingEngine)]

debug

  1. This converter is used as debug tool. It dumps on screen the content and the
  2. type of the input sample. The sample is returned as is on its output. This
  3. converter only exists when haproxy was built with debugging enabled.

div()

  1. Divides the input value of type signed integer by <value>, and returns the
  2. result as an signed integer. If <value> is null, the largest unsigned
  3. integer is returned (typically 2^63-1). <value> can be a numeric value or a
  4. variable name. The name of the variable starts with an indication about its
  5. scope. The scopes allowed are:
  6. "proc" : the variable is shared with the whole process
  7. "sess" : the variable is shared with the whole session
  8. "txn" : the variable is shared with the transaction (request and response)
  9. "req" : the variable is shared only during request processing
  10. "res" : the variable is shared only during response processing
  11. This prefix is followed by a name. The separator is a '.'. The name may only
  12. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

djb2([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the DJB2
  2. hash function. Optionally, it is possible to apply a full avalanche hash
  3. function to the output if the optional <avalanche> argument equals 1. This
  4. converter uses the same functions as used by the various hash-based load
  5. balancing algorithms, so it will provide exactly the same results. It is
  6. mostly intended for debugging, but can be used as a stick-table entry to
  7. collect rough statistics. It must not be used for security purposes as a
  8. 32-bit hash is trivial to break. See also "crc32", "sdbm", "wt6", "crc32c",
  9. and the "hash-type" directive.

even

  1. Returns a boolean TRUE if the input value of type signed integer is even
  2. otherwise returns FALSE. It is functionally equivalent to "not,and(1),bool".

field(,[,])

  1. Extracts the substring at the given index counting from the beginning
  2. (positive index) or from the end (negative index) considering given delimiters
  3. from an input string. Indexes start at 1 or -1 and delimiters are a string
  4. formatted list of chars. Optionally you can specify <count> of fields to
  5. extract (default: 1). Value of 0 indicates extraction of all remaining
  6. fields.

Example :

  1. str(f1_f2_f3__f5),field(5,_) # f5
  2. str(f1_f2_f3__f5),field(2,_,0) # f2_f3__f5
  3. str(f1_f2_f3__f5),field(2,_,2) # f2_f3
  4. str(f1_f2_f3__f5),field(-2,_,3) # f2_f3_
  5. str(f1_f2_f3__f5),field(-3,_,0) # f1_f2_f3

hex

  1. Converts a binary input sample to a hex string containing two hex digits per
  2. input byte. It is used to log or transfer hex dumps of some binary input data
  3. in a way that can be reliably transferred (e.g. an SSL ID can be copied in a
  4. header).

hex2i

  1. Converts a hex string containing two hex digits per input byte to an
  2. integer. If the input value cannot be converted, then zero is returned.

http_date([])

  1. Converts an integer supposed to contain a date since epoch to a string
  2. representing this date in a format suitable for use in HTTP header fields. If
  3. an offset value is specified, then it is a number of seconds that is added to
  4. the date before the conversion is operated. This is particularly useful to
  5. emit Date header fields, Expires values in responses when combined with a
  6. positive offset, or Last-Modified values when the offset is negative.

in_table(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, a boolean false
  3. is returned. Otherwise a boolean true is returned. This can be used to verify
  4. the presence of a certain key in a table tracking some elements (e.g. whether
  5. or not a source IP address or an Authorization header was already seen).
  6.  
  7. ipmask(<mask4>, [<mask6>])
  8. Apply a mask to an IP address, and use the result for lookups and storage.
  9. This can be used to make all hosts within a certain mask to share the same
  10. table entries and as such use the same server. The mask4 can be passed in
  11. dotted form (e.g. 255.255.255.0) or in CIDR form (e.g. 24). The mask6 can
  12. be passed in quadruplet form (e.g. ffff:ffff::) or in CIDR form (e.g. 64).
  13. If no mask6 is given IPv6 addresses will fail to convert for backwards
  14. compatibility reasons.

json([])

  1. Escapes the input string and produces an ASCII output string ready to use as a
  2. JSON string. The converter tries to decode the input string according to the
  3. <input-code> parameter. It can be "ascii", "utf8", "utf8s", "utf8p" or
  4. "utf8ps". The "ascii" decoder never fails. The "utf8" decoder detects 3 types
  5. of errors:
  6. - bad UTF-8 sequence (lone continuation byte, bad number of continuation
  7. bytes, ...)
  8. - invalid range (the decoded value is within a UTF-8 prohibited range),
  9. - code overlong (the value is encoded with more bytes than necessary).
  10.  
  11. The UTF-8 JSON encoding can produce a "too long value" error when the UTF-8
  12. character is greater than 0xffff because the JSON string escape specification
  13. only authorizes 4 hex digits for the value encoding. The UTF-8 decoder exists
  14. in 4 variants designated by a combination of two suffix letters : "p" for
  15. "permissive" and "s" for "silently ignore". The behaviors of the decoders
  16. are :
  17. - "ascii" : never fails;
  18. - "utf8" : fails on any detected errors;
  19. - "utf8s" : never fails, but removes characters corresponding to errors;
  20. - "utf8p" : accepts and fixes the overlong errors, but fails on any other
  21. error;
  22. - "utf8ps" : never fails, accepts and fixes the overlong errors, but removes
  23. characters corresponding to the other errors.
  24.  
  25. This converter is particularly useful for building properly escaped JSON for
  26. logging to servers which consume JSON-formatted traffic logs.

Example:

  1. capture request header Host len 15
  2. capture request header user-agent len 150
  3. log-format &#x27;{"ip":"%[src]","user-agent":"%[capture.req.hdr(1),json(utf8s)]"}'
  1. Input request from client 127.0.0.1:
  2. GET / HTTP/1.0
  3. User-Agent: Very "Ugly" UA 1/2
  4.  
  5. Output log:
  6. {"ip":"127.0.0.1","user-agent":"Very \"Ugly\" UA 1\/2"}

language([,])

  1. Returns the value with the highest q-factor from a list as extracted from the
  2. "accept-language" header using "req.fhdr". Values with no q-factor have a
  3. q-factor of 1. Values with a q-factor of 0 are dropped. Only values which
  4. belong to the list of semi-colon delimited <values> will be considered. The
  5. argument <value> syntax is "lang[;lang[;lang[;...]]]". If no value matches the
  6. given list and a default value is provided, it is returned. Note that language
  7. names may have a variant after a dash ('-'). If this variant is present in the
  8. list, it will be matched, but if it is not, only the base language is checked.
  9. The match is case-sensitive, and the output string is always one of those
  10. provided in arguments. The ordering of arguments is meaningless, only the
  11. ordering of the values in the request counts, as the first value among
  12. multiple sharing the same q-factor is used.

Example :

  1. # this configuration switches to the backend matching a
  2. # given language based on the request :
  3. acl es req.fhdr(accept-language),language(es;fr;en) -m str es
  4. acl fr req.fhdr(accept-language),language(es;fr;en) -m str fr
  5. acl en req.fhdr(accept-language),language(es;fr;en) -m str en
  6. use_backend spanish if es
  7. use_backend french if fr
  8. use_backend english if en
  9. default_backend choose_your_language

length

  1. Get the length of the string. This can only be placed after a string
  2. sample fetch function or after a transformation keyword returning a string
  3. type. The result is of type integer.

lower

  1. Convert a string sample to lower case. This can only be placed after a string
  2. sample fetch function or after a transformation keyword returning a string
  3. type. The result is of type string.

ltime([,])

  1. Converts an integer supposed to contain a date since epoch to a string
  2. representing this date in local time using a format defined by the <format>
  3. string using strftime(3). The purpose is to allow any date format to be used
  4. in logs. An optional <offset> in seconds may be applied to the input date
  5. (positive or negative). See the strftime() man page for the format supported
  6. by your operating system. See also the utime converter.

Example :

  1. # Emit two colons, one with the local time and another with ip:port
  2. # e.g. 20140710162350 127.0.0.1:57325
  3. log-format %[date,ltime(%Y%m%d%H%M%S)]\ %ci:%cp

map([,])

  1. map_<match_type>(<map_file>[,<default_value>])
  2. map_<match_type>_<output_type>(<map_file>[,<default_value>])
  3. Search the input value from <map_file> using the <match_type> matching method,
  4. and return the associated value converted to the type <output_type>. If the
  5. input value cannot be found in the <map_file>, the converter returns the
  6. <default_value>. If the <default_value> is not set, the converter fails and
  7. acts as if no input value could be fetched. If the <match_type> is not set, it
  8. defaults to "str". Likewise, if the <output_type> is not set, it defaults to
  9. "str". For convenience, the "map" keyword is an alias for "map_str" and maps a
  10. string to another string.
  11.  
  12. It is important to avoid overlapping between the keys : IP addresses and
  13. strings are stored in trees, so the first of the finest match will be used.
  14. Other keys are stored in lists, so the first matching occurrence will be used.
  15.  
  16. The following array contains the list of all map functions available sorted by
  17. input type, match type and output type.
input typematch methodoutput type stroutput type intoutput type ip
strstrmap_strmap_str_intmap_str_ip
strbegmap_begmap_beg_intmap_end_ip
strsubmap_submap_sub_intmap_sub_ip
strdirmap_dirmap_dir_intmap_dir_ip
strdommap_dommap_dom_intmap_dom_ip
strendmap_endmap_end_intmap_end_ip
strregmap_regmap_reg_intmap_reg_ip
strregmap_regmmap_reg_intmap_reg_ip
intintmap_intmap_int_intmap_int_ip
ipipmap_ipmap_ip_intmap_ip_ip
  1. The special map called "map_regm" expect matching zone in the regular
  2. expression and modify the output replacing back reference (like "\1") by
  3. the corresponding match text.
  4.  
  5. The file contains one key + value per line. Lines which start with '#' are
  6. ignored, just like empty lines. Leading tabs and spaces are stripped. The key
  7. is then the first "word" (series of non-space/tabs characters), and the value
  8. is what follows this series of space/tab till the end of the line excluding
  9. trailing spaces/tabs.

Example :

  1. # this is a comment and is ignored
  2. 2.22.246.0/23 United Kingdom \n
  3. <-><-----------><--><------------><---->
  4. | | | | `- trailing spaces ignored
  5. | | | `---------- value
  6. | | `-------------------- middle spaces ignored
  7. | `---------------------------- key
  8. `------------------------------------ leading spaces ignored

mod()

  1. Divides the input value of type signed integer by <value>, and returns the
  2. remainder as an signed integer. If <value> is null, then zero is returned.
  3. <value> can be a numeric value or a variable name. The name of the variable
  4. starts with an indication about its scope. The scopes allowed are:
  5. "proc" : the variable is shared with the whole process
  6. "sess" : the variable is shared with the whole session
  7. "txn" : the variable is shared with the transaction (request and response)
  8. "req" : the variable is shared only during request processing
  9. "res" : the variable is shared only during response processing
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

mul()

  1. Multiplies the input value of type signed integer by <value>, and returns
  2. the product as an signed integer. In case of overflow, the largest possible
  3. value for the sign is returned so that the operation doesn't wrap around.
  4. <value> can be a numeric value or a variable name. The name of the variable
  5. starts with an indication about its scope. The scopes allowed are:
  6. "proc" : the variable is shared with the whole process
  7. "sess" : the variable is shared with the whole session
  8. "txn" : the variable is shared with the transaction (request and response)
  9. "req" : the variable is shared only during request processing
  10. "res" : the variable is shared only during response processing
  11. This prefix is followed by a name. The separator is a '.'. The name may only
  12. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

nbsrv

  1. Takes an input value of type string, interprets it as a backend name and
  2. returns the number of usable servers in that backend. Can be used in places
  3. where we want to look up a backend from a dynamic name, like a result of a
  4. map lookup.

neg

  1. Takes the input value of type signed integer, computes the opposite value,
  2. and returns the remainder as an signed integer. 0 is identity. This operator
  3. is provided for reversed subtracts : in order to subtract the input from a
  4. constant, simply perform a "neg,add(value)".

not

  1. Returns a boolean FALSE if the input value of type signed integer is
  2. non-null, otherwise returns TRUE. Used in conjunction with and(), it can be
  3. used to report true/false for bit testing on input values (e.g. verify the
  4. absence of a flag).

odd

  1. Returns a boolean TRUE if the input value of type signed integer is odd
  2. otherwise returns FALSE. It is functionally equivalent to "and(1),bool".

or()

  1. Performs a bitwise "OR" between <value> and the input value of type signed
  2. integer, and returns the result as an signed integer. <value> can be a
  3. numeric value or a variable name. The name of the variable starts with an
  4. indication about its scope. The scopes allowed are:
  5. "proc" : the variable is shared with the whole process
  6. "sess" : the variable is shared with the whole session
  7. "txn" : the variable is shared with the transaction (request and response)
  8. "req" : the variable is shared only during request processing
  9. "res" : the variable is shared only during response processing
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

protobuf(,[])

  1. This extracts the protocol buffers message field in raw mode of an input binary
  2. sample representation of a protocol buffer message with <field_number> as field
  3. number (dotted notation) if <field_type> is not present, or as an integer sample
  4. if this field is present (see also "ungrpc" below).
  5. The list of the authorized types is the following one: "int32", "int64", "uint32",
  6. "uint64", "sint32", "sint64", "bool", "enum" for the "varint" wire type 0
  7. "fixed64", "sfixed64", "double" for the 64bit wire type 1, "fixed32", "sfixed32",
  8. "float" for the wire type 5. Note that "string" is considered as a length-delimited
  9. type, so it does not require any <field_type> argument to be extracted.
  10. More information may be found here about the protocol buffers message field types:
  11. https://developers.google.com/protocol-buffers/docs/encoding

regsub(,[,])

  1. Applies a regex-based substitution to the input string. It does the same
  2. operation as the well-known "sed" utility with "s/<regex>/<subst>/". By
  3. default it will replace in the input string the first occurrence of the
  4. largest part matching the regular expression <regex> with the substitution
  5. string <subst>. It is possible to replace all occurrences instead by adding
  6. the flag "g" in the third argument <flags>. It is also possible to make the
  7. regex case insensitive by adding the flag "i" in <flags>. Since <flags> is a
  8. string, it is made up from the concatenation of all desired flags. Thus if
  9. both "i" and "g" are desired, using "gi" or "ig" will have the same effect.
  10. It is important to note that due to the current limitations of the
  11. configuration parser, some characters such as closing parenthesis, closing
  12. square brackets or comma are not possible to use in the arguments. The first
  13. use of this converter is to replace certain characters or sequence of
  14. characters with other ones.

Example :

  1. # de-duplicate "/" in header "x-path".
  2. # input: x-path: /////a///b/c/xzxyz/
  3. # output: x-path: /a/b/c/xzxyz/
  4. http-request set-header x-path %[hdr(x-path),regsub(/+,/,g)]

capture-req()

  1. Capture the string entry in the request slot <id> and returns the entry as
  2. is. If the slot doesn't exist, the capture fails silently.

See also:declare capture“, “http-request capture“, “http-response capture“, “capture.req.hdr“ and “capture.res.hdr“ (sample fetches).

capture-res()

  1. Capture the string entry in the response slot <id> and returns the entry as
  2. is. If the slot doesn't exist, the capture fails silently.

See also:declare capture“, “http-request capture“, “http-response capture“, “capture.req.hdr“ and “capture.res.hdr“ (sample fetches).

sdbm([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the SDBM
  2. hash function. Optionally, it is possible to apply a full avalanche hash
  3. function to the output if the optional <avalanche> argument equals 1. This
  4. converter uses the same functions as used by the various hash-based load
  5. balancing algorithms, so it will provide exactly the same results. It is
  6. mostly intended for debugging, but can be used as a stick-table entry to
  7. collect rough statistics. It must not be used for security purposes as a
  8. 32-bit hash is trivial to break. See also "crc32", "djb2", "wt6", "crc32c",
  9. and the "hash-type" directive.
  10.  
  11. set-var(<var name>)
  12. Sets a variable with the input content and returns the content on the output
  13. as-is. The variable keeps the value and the associated input type. The name of
  14. the variable starts with an indication about its scope. The scopes allowed are:
  15. "proc" : the variable is shared with the whole process
  16. "sess" : the variable is shared with the whole session
  17. "txn" : the variable is shared with the transaction (request and
  18. response),
  19. "req" : the variable is shared only during request processing,
  20. "res" : the variable is shared only during response processing.
  21. This prefix is followed by a name. The separator is a '.'. The name may only
  22. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

sha1

  1. Converts a binary input sample to a SHA1 digest. The result is a binary
  2. sample with length of 20 bytes.

strcmp()

  1. Compares the contents of <var> with the input value of type string. Returns
  2. the result as a signed integer compatible with strcmp(3): 0 if both strings
  3. are identical. A value less than 0 if the left string is lexicographically
  4. smaller than the right string or if the left string is shorter. A value greater
  5. than 0 otherwise (right string greater than left string or the right string is
  6. shorter).

Example :

  1. http-request set-var(txn.host) hdr(host)
  2. # Check whether the client is attempting domain fronting.
  3. acl ssl_sni_http_host_match ssl_fc_sni,strcmp(txn.host) eq 0

sub()

  1. Subtracts <value> from the input value of type signed integer, and returns
  2. the result as an signed integer. Note: in order to subtract the input from
  3. a constant, simply perform a "neg,add(value)". <value> can be a numeric value
  4. or a variable name. The name of the variable starts with an indication about
  5. its scope. The scopes allowed are:
  6. "proc" : the variable is shared with the whole process
  7. "sess" : the variable is shared with the whole session
  8. "txn" : the variable is shared with the transaction (request and
  9. response),
  10. "req" : the variable is shared only during request processing,
  11. "res" : the variable is shared only during response processing.
  12. This prefix is followed by a name. The separator is a '.'. The name may only
  13. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

table_bytes_in_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the average client-to-server
  4. bytes rate associated with the input sample in the designated table, measured
  5. in amount of bytes over the period configured in the table. See also the
  6. sc_bytes_in_rate sample fetch keyword.

table_bytes_out_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the average server-to-client
  4. bytes rate associated with the input sample in the designated table, measured
  5. in amount of bytes over the period configured in the table. See also the
  6. sc_bytes_out_rate sample fetch keyword.

table_conn_cnt(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of incoming
  4. connections associated with the input sample in the designated table. See
  5. also the sc_conn_cnt sample fetch keyword.

table_conn_cur(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the current amount of concurrent
  4. tracked connections associated with the input sample in the designated table.
  5. See also the sc_conn_cur sample fetch keyword.

table_conn_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the average incoming connection
  4. rate associated with the input sample in the designated table. See also the
  5. sc_conn_rate sample fetch keyword.

table_gpt0(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, boolean value zero
  3. is returned. Otherwise the converter returns the current value of the first
  4. general purpose tag associated with the input sample in the designated table.
  5. See also the sc_get_gpt0 sample fetch keyword.

table_gpc0(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the current value of the first
  4. general purpose counter associated with the input sample in the designated
  5. table. See also the sc_get_gpc0 sample fetch keyword.

table_gpc0_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the frequency which the gpc0
  4. counter was incremented over the configured period in the table, associated
  5. with the input sample in the designated table. See also the sc_get_gpc0_rate
  6. sample fetch keyword.

table_gpc1(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the current value of the second
  4. general purpose counter associated with the input sample in the designated
  5. table. See also the sc_get_gpc1 sample fetch keyword.

table_gpc1_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the frequency which the gpc1
  4. counter was incremented over the configured period in the table, associated
  5. with the input sample in the designated table. See also the sc_get_gpc1_rate
  6. sample fetch keyword.

table_http_err_cnt(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of HTTP
  4. errors associated with the input sample in the designated table. See also the
  5. sc_http_err_cnt sample fetch keyword.

table_http_err_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the average rate of HTTP errors associated with the
  4. input sample in the designated table, measured in amount of errors over the
  5. period configured in the table. See also the sc_http_err_rate sample fetch
  6. keyword.

table_http_req_cnt(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of HTTP
  4. requests associated with the input sample in the designated table. See also
  5. the sc_http_req_cnt sample fetch keyword.

table_http_req_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the average rate of HTTP requests associated with the
  4. input sample in the designated table, measured in amount of requests over the
  5. period configured in the table. See also the sc_http_req_rate sample fetch
  6. keyword.

table_kbytes_in(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of client-
  4. to-server data associated with the input sample in the designated table,
  5. measured in kilobytes. The test is currently performed on 32-bit integers,
  6. which limits values to 4 terabytes. See also the sc_kbytes_in sample fetch
  7. keyword.

table_kbytes_out(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of server-
  4. to-client data associated with the input sample in the designated table,
  5. measured in kilobytes. The test is currently performed on 32-bit integers,
  6. which limits values to 4 terabytes. See also the sc_kbytes_out sample fetch
  7. keyword.

table_server_id(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the server ID associated with
  4. the input sample in the designated table. A server ID is associated to a
  5. sample by a "stick" rule when a connection to a server succeeds. A server ID
  6. zero means that no server is associated with this key.

table_sess_cnt(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the cumulative number of incoming
  4. sessions associated with the input sample in the designated table. Note that
  5. a session here refers to an incoming connection being accepted by the
  6. "tcp-request connection" rulesets. See also the sc_sess_cnt sample fetch
  7. keyword.

table_sess_rate(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the average incoming session
  4. rate associated with the input sample in the designated table. Note that a
  5. session here refers to an incoming connection being accepted by the
  6. "tcp-request connection" rulesets. See also the sc_sess_rate sample fetch
  7. keyword.

table_trackers(

)

  1. Uses the string representation of the input sample to perform a look up in
  2. the specified table. If the key is not found in the table, integer value zero
  3. is returned. Otherwise the converter returns the current amount of concurrent
  4. connections tracking the same key as the input sample in the designated
  5. table. It differs from table_conn_cur in that it does not rely on any stored
  6. information but on the table's reference count (the "use" value which is
  7. returned by "show table" on the CLI). This may sometimes be more suited for
  8. layer7 tracking. It can be used to tell a server how many concurrent
  9. connections there are from a given address for example. See also the
  10. sc_trackers sample fetch keyword.

upper

  1. Convert a string sample to upper case. This can only be placed after a string
  2. sample fetch function or after a transformation keyword returning a string
  3. type. The result is of type string.

url_dec

  1. Takes an url-encoded string provided as input and returns the decoded
  2. version as output. The input and the output are of type string.

ungrpc(,[])

  1. This extracts the protocol buffers message field in raw mode of an input binary
  2. sample representation of a gRPC message with <field_number> as field number
  3. (dotted notation) if <field_type> is not present, or as an integer sample if this
  4. field is present.
  5. The list of the authorized types is the following one: "int32", "int64", "uint32",
  6. "uint64", "sint32", "sint64", "bool", "enum" for the "varint" wire type 0
  7. "fixed64", "sfixed64", "double" for the 64bit wire type 1, "fixed32", "sfixed32",
  8. "float" for the wire type 5. Note that "string" is considered as a length-delimited
  9. type, so it does not require any <field_type> argument to be extracted.
  10. More information may be found here about the protocol buffers message field types:
  11. https://developers.google.com/protocol-buffers/docs/encoding

Example:

  1. // with such a protocol buffer .proto file content adapted from
  2. // https://github.com/grpc/grpc/blob/master/examples/protos/route_guide.proto
  3. message Point {
  4. int32 latitude = 1;
  5. int32 longitude = 2;
  6. }
  7. message PPoint {
  8. Point point = 59;
  9. }
  10. message Rectangle {
  11. // One corner of the rectangle.
  12. PPoint lo = 48;
  13. // The other corner of the rectangle.
  14. PPoint hi = 49;
  15. }
  16. let&#x27;s say a body request is made of a "Rectangle" object value (two PPoint
  17. protocol buffers messages), the four protocol buffers fields could be
  18. extracted with these "ungrpc" directives:
  19. req.body,ungrpc(48.59.1,int32) # "latitude" of "lo" first PPoint
  20. req.body,ungrpc(48.59.2,int32) # "longitude" of "lo" first PPoint
  21. req.body,ungrpc(49.59.1,int32) # "latitude" of "hi" second PPoint
  22. req.body,ungrpc(49.59.2,int32) # "longitude" of "hi" second PPoint
  23. We could also extract the intermediary 48.59 field as a binary sample as follows:
  24. req.body,ungrpc(48.59)
  25. As a gRPC message is always made of a gRPC header followed by protocol buffers
  26. messages, in the previous example the "latitude" of "lo" first PPoint
  27. could be extracted with these equivalent directives:
  28. req.body,ungrpc(48.59),protobuf(1,int32)
  29. req.body,ungrpc(48),protobuf(59.1,int32)
  30. req.body,ungrpc(48),protobuf(59),protobuf(1,int32)
  31. Note that the first convert must be "ungrpc", the remaining ones must be
  32. "protobuf" and only the last one may have or not a second argument to
  33. interpret the previous binary sample.
  1. unset-var(<var name>)
  2. Unsets a variable if the input content is defined. The name of the variable
  3. starts with an indication about its scope. The scopes allowed are:
  4. "proc" : the variable is shared with the whole process
  5. "sess" : the variable is shared with the whole session
  6. "txn" : the variable is shared with the transaction (request and
  7. response),
  8. "req" : the variable is shared only during request processing,
  9. "res" : the variable is shared only during response processing.
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

utime([,])

  1. Converts an integer supposed to contain a date since epoch to a string
  2. representing this date in UTC time using a format defined by the <format>
  3. string using strftime(3). The purpose is to allow any date format to be used
  4. in logs. An optional <offset> in seconds may be applied to the input date
  5. (positive or negative). See the strftime() man page for the format supported
  6. by your operating system. See also the ltime converter.

Example :

  1. # Emit two colons, one with the UTC time and another with ip:port
  2. # e.g. 20140710162350 127.0.0.1:57325
  3. log-format %[date,utime(%Y%m%d%H%M%S)]\ %ci:%cp

word(,[,])

  1. Extracts the nth word counting from the beginning (positive index) or from
  2. the end (negative index) considering given delimiters from an input string.
  3. Indexes start at 1 or -1 and delimiters are a string formatted list of chars.
  4. Delimiters at the beginning or end of the input string are ignored.
  5. Optionally you can specify <count> of words to extract (default: 1).
  6. Value of 0 indicates extraction of all remaining words.

Example :

  1. str(f1_f2_f3__f5),word(4,_) # f5
  2. str(f1_f2_f3__f5),word(2,_,0) # f2_f3__f5
  3. str(f1_f2_f3__f5),word(3,_,2) # f3__f5
  4. str(f1_f2_f3__f5),word(-2,_,3) # f1_f2_f3
  5. str(f1_f2_f3__f5),word(-3,_,0) # f1_f2
  6. str(/f1/f2/f3/f4),word(1,/) # f1

wt6([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the WT6
  2. hash function. Optionally, it is possible to apply a full avalanche hash
  3. function to the output if the optional <avalanche> argument equals 1. This
  4. converter uses the same functions as used by the various hash-based load
  5. balancing algorithms, so it will provide exactly the same results. It is
  6. mostly intended for debugging, but can be used as a stick-table entry to
  7. collect rough statistics. It must not be used for security purposes as a
  8. 32-bit hash is trivial to break. See also "crc32", "djb2", "sdbm", "crc32c",
  9. and the "hash-type" directive.

xor()

  1. Performs a bitwise "XOR" (exclusive OR) between <value> and the input value
  2. of type signed integer, and returns the result as an signed integer.
  3. <value> can be a numeric value or a variable name. The name of the variable
  4. starts with an indication about its scope. The scopes allowed are:
  5. "proc" : the variable is shared with the whole process
  6. "sess" : the variable is shared with the whole session
  7. "txn" : the variable is shared with the transaction (request and
  8. response),
  9. "req" : the variable is shared only during request processing,
  10. "res" : the variable is shared only during response processing.
  11. This prefix is followed by a name. The separator is a '.'. The name may only
  12. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

xxh32([])

  1. Hashes a binary input sample into an unsigned 32-bit quantity using the 32-bit
  2. variant of the XXHash hash function. This hash supports a seed which defaults
  3. to zero but a different value maybe passed as the <seed> argument. This hash
  4. is known to be very good and very fast so it can be used to hash URLs and/or
  5. URL parameters for use as stick-table keys to collect statistics with a low
  6. collision rate, though care must be taken as the algorithm is not considered
  7. as cryptographically secure.

xxh64([])

  1. Hashes a binary input sample into a signed 64-bit quantity using the 64-bit
  2. variant of the XXHash hash function. This hash supports a seed which defaults
  3. to zero but a different value maybe passed as the <seed> argument. This hash
  4. is known to be very good and very fast so it can be used to hash URLs and/or
  5. URL parameters for use as stick-table keys to collect statistics with a low
  6. collision rate, though care must be taken as the algorithm is not considered
  7. as cryptographically secure.

7.3.2. Fetching samples from internal states

  1. A first set of sample fetch methods applies to internal information which does
  2. not even relate to any client information. These ones are sometimes used with
  3. "monitor-fail" directives to report an internal status to external watchers.
  4. The sample fetch methods described in this section are usable anywhere.

always_false : boolean

  1. Always returns the boolean "false" value. It may be used with ACLs as a
  2. temporary replacement for another one when adjusting configurations.

always_true : boolean

  1. Always returns the boolean "true" value. It may be used with ACLs as a
  2. temporary replacement for another one when adjusting configurations.

avg_queue([]) : integer

  1. Returns the total number of queued connections of the designated backend
  2. divided by the number of active servers. The current backend is used if no
  3. backend is specified. This is very similar to "queue" except that the size of
  4. the farm is considered, in order to give a more accurate measurement of the
  5. time it may take for a new connection to be processed. The main usage is with
  6. ACL to return a sorry page to new users when it becomes certain they will get
  7. a degraded service, or to pass to the backend servers in a header so that
  8. they decide to work in degraded mode or to disable some functions to speed up
  9. the processing a bit. Note that in the event there would not be any active
  10. server anymore, twice the number of queued connections would be considered as
  11. the measured value. This is a fair estimate, as we expect one server to get
  12. back soon anyway, but we still prefer to send new traffic to another backend
  13. if in better shape. See also the "queue", "be_conn", and "be_sess_rate"
  14. sample fetches.

be_conn([]) : integer

  1. Applies to the number of currently established connections on the backend,
  2. possibly including the connection being evaluated. If no backend name is
  3. specified, the current one is used. But it is also possible to check another
  4. backend. It can be used to use a specific farm when the nominal one is full.
  5. See also the "fe_conn", "queue", "be_conn_free", and "be_sess_rate" criteria.

be_conn_free([]) : integer

  1. Returns an integer value corresponding to the number of available connections
  2. across available servers in the backend. Queue slots are not included. Backup
  3. servers are also not included, unless all other servers are down. If no
  4. backend name is specified, the current one is used. But it is also possible
  5. to check another backend. It can be used to use a specific farm when the
  6. nominal one is full. See also the "be_conn", "connslots", and "srv_conn_free"
  7. criteria.
  8.  
  9. OTHER CAVEATS AND NOTES: if any of the server maxconn, or maxqueue is 0
  10. (meaning unlimited), then this fetch clearly does not make sense, in which
  11. case the value returned will be -1.

be_sess_rate([]) : integer

  1. Returns an integer value corresponding to the sessions creation rate on the
  2. backend, in number of new sessions per second. This is used with ACLs to
  3. switch to an alternate backend when an expensive or fragile one reaches too
  4. high a session rate, or to limit abuse of service (e.g. prevent sucking of an
  5. online dictionary). It can also be useful to add this element to logs using a
  6. log-format directive.

Example :

  1. # Redirect to an error page if the dictionary is requested too often
  2. backend dynamic
  3. mode http
  4. acl being_scanned be_sess_rate gt 100
  5. redirect location /denied.html if being_scanned

bin() : bin

  1. Returns a binary chain. The input is the hexadecimal representation
  2. of the string.

bool() : bool

  1. Returns a boolean value. <bool> can be 'true', 'false', '1' or '0'.
  2. 'false' and '0' are the same. 'true' and '1' are the same.

connslots([]) : integer

  1. Returns an integer value corresponding to the number of connection slots
  2. still available in the backend, by totaling the maximum amount of
  3. connections on all servers and the maximum queue size. This is probably only
  4. used with ACLs.
  5.  
  6. The basic idea here is to be able to measure the number of connection "slots"
  7. still available (connection + queue), so that anything beyond that (intended
  8. usage; see "use_backend" keyword) can be redirected to a different backend.
  9.  
  10. 'connslots' = number of available server connection slots, + number of
  11. available server queue slots.
  12.  
  13. Note that while "fe_conn" may be used, "connslots" comes in especially
  14. useful when you have a case of traffic going to one single ip, splitting into
  15. multiple backends (perhaps using ACLs to do name-based load balancing) and
  16. you want to be able to differentiate between different backends, and their
  17. available "connslots". Also, whereas "nbsrv" only measures servers that are
  18. actually *down*, this fetch is more fine-grained and looks into the number of
  19. available connection slots as well. See also "queue" and "avg_queue".
  20.  
  21. OTHER CAVEATS AND NOTES: at this point in time, the code does not take care
  22. of dynamic connections. Also, if any of the server maxconn, or maxqueue is 0,
  23. then this fetch clearly does not make sense, in which case the value returned
  24. will be -1.

cpu_calls : integer

  1. Returns the number of calls to the task processing the stream or current
  2. request since it was allocated. This number is reset for each new request on
  3. the same connections in case of HTTP keep-alive. This value should usually be
  4. low and stable (around 2 calls for a typically simple request) but may become
  5. high if some processing (compression, caching or analysis) is performed. This
  6. is purely for performance monitoring purposes.

cpu_ns_avg : integer

  1. Returns the average number of nanoseconds spent in each call to the task
  2. processing the stream or current request. This number is reset for each new
  3. request on the same connections in case of HTTP keep-alive. This value
  4. indicates the overall cost of processing the request or the connection for
  5. each call. There is no good nor bad value but the time spent in a call
  6. automatically causes latency for other processing (see lat_ns_avg below),
  7. and may affect other connection's apparent response time. Certain operations
  8. like compression, complex regex matching or heavy Lua operations may directly
  9. affect this value, and having it in the logs will make it easier to spot the
  10. faulty processing that needs to be fixed to recover decent performance.
  11. Note: this value is exactly cpu_ns_tot divided by cpu_calls.

cpu_ns_tot : integer

  1. Returns the total number of nanoseconds spent in each call to the task
  2. processing the stream or current request. This number is reset for each new
  3. request on the same connections in case of HTTP keep-alive. This value
  4. indicates the overall cost of processing the request or the connection for
  5. each call. There is no good nor bad value but the time spent in a call
  6. automatically causes latency for other processing (see lat_ns_avg below),
  7. induces CPU costs on the machine, and may affect other connection's apparent
  8. response time. Certain operations like compression, complex regex matching or
  9. heavy Lua operations may directly affect this value, and having it in the
  10. logs will make it easier to spot the faulty processing that needs to be fixed
  11. to recover decent performance. The value may be artificially high due to a
  12. high cpu_calls count, for example when processing many HTTP chunks, and for
  13. this reason it is often preferred to log cpu_ns_avg instead.

date([]) : integer

  1. Returns the current date as the epoch (number of seconds since 01/01/1970).
  2. If an offset value is specified, then it is a number of seconds that is added
  3. to the current date before returning the value. This is particularly useful
  4. to compute relative dates, as both positive and negative offsets are allowed.
  5. It is useful combined with the http_date converter.

Example :

  1. # set an expires header to now+1 hour in every response
  2. http-response set-header Expires %[date(3600),http_date]

date_us : integer

  1. Return the microseconds part of the date (the "second" part is returned by
  2. date sample). This sample is coherent with the date sample as it is comes
  3. from the same timeval structure.

distcc_body([,]) : binary

  1. Parses a distcc message and returns the body associated to occurrence #<occ>
  2. of the token <token>. Occurrences start at 1, and when unspecified, any may
  3. match though in practice only the first one is checked for now. This can be
  4. used to extract file names or arguments in files built using distcc through
  5. haproxy. Please refer to distcc's protocol documentation for the complete
  6. list of supported tokens.

distcc_param([,]) : integer

  1. Parses a distcc message and returns the parameter associated to occurrence
  2. #<occ> of the token <token>. Occurrences start at 1, and when unspecified,
  3. any may match though in practice only the first one is checked for now. This
  4. can be used to extract certain information such as the protocol version, the
  5. file size or the argument in files built using distcc through haproxy.
  6. Another use case consists in waiting for the start of the preprocessed file
  7. contents before connecting to the server to avoid keeping idle connections.
  8. Please refer to distcc's protocol documentation for the complete list of
  9. supported tokens.

Example :

  1. # wait up to 20s for the pre-processed file to be uploaded
  2. tcp-request inspect-delay 20s
  3. tcp-request content accept if { distcc_param(DOTI) -m found }
  4. # send large files to the big farm
  5. use_backend big_farm if { distcc_param(DOTI) gt 1000000 }

env() : string

  1. Returns a string containing the value of environment variable <name>. As a
  2. reminder, environment variables are per-process and are sampled when the
  3. process starts. This can be useful to pass some information to a next hop
  4. server, or with ACLs to take specific action when the process is started a
  5. certain way.

Examples :

  1. # Pass the Via header to next hop with the local hostname in it
  2. http-request add-header Via 1.1\ %[env(HOSTNAME)]
  3. # reject cookie-less requests when the STOP environment variable is set
  4. http-request deny if !{ cook(SESSIONID) -m found } { env(STOP) -m found }

fe_conn([]) : integer

  1. Returns the number of currently established connections on the frontend,
  2. possibly including the connection being evaluated. If no frontend name is
  3. specified, the current one is used. But it is also possible to check another
  4. frontend. It can be used to return a sorry page before hard-blocking, or to
  5. use a specific backend to drain new requests when the farm is considered
  6. full. This is mostly used with ACLs but can also be used to pass some
  7. statistics to servers in HTTP headers. See also the "dst_conn", "be_conn",
  8. "fe_sess_rate" fetches.

fe_req_rate([]) : integer

  1. Returns an integer value corresponding to the number of HTTP requests per
  2. second sent to a frontend. This number can differ from "fe_sess_rate" in
  3. situations where client-side keep-alive is enabled.

fe_sess_rate([]) : integer

  1. Returns an integer value corresponding to the sessions creation rate on the
  2. frontend, in number of new sessions per second. This is used with ACLs to
  3. limit the incoming session rate to an acceptable range in order to prevent
  4. abuse of service at the earliest moment, for example when combined with other
  5. layer 4 ACLs in order to force the clients to wait a bit for the rate to go
  6. down below the limit. It can also be useful to add this element to logs using
  7. a log-format directive. See also the "rate-limit sessions" directive for use
  8. in frontends.

Example :

  1. # This frontend limits incoming mails to 10/s with a max of 100
  2. # concurrent connections. We accept any connection below 10/s, and
  3. # force excess clients to wait for 100 ms. Since clients are limited to
  4. # 100 max, there cannot be more than 10 incoming mails per second.
  5. frontend mail
  6. bind :25
  7. mode tcp
  8. maxconn 100
  9. acl too_fast fe_sess_rate ge 10
  10. tcp-request inspect-delay 100ms
  11. tcp-request content accept if ! too_fast
  12. tcp-request content accept if WAIT_END

hostname : string

  1. Returns the system hostname.

int() : signed integer

  1. Returns a signed integer.

ipv4() : ipv4

  1. Returns an ipv4.

ipv6() : ipv6

  1. Returns an ipv6.

lat_ns_avg : integer

  1. Returns the average number of nanoseconds spent between the moment the task
  2. handling the stream is woken up and the moment it is effectively called. This
  3. number is reset for each new request on the same connections in case of HTTP
  4. keep-alive. This value indicates the overall latency inflicted to the current
  5. request by all other requests being processed in parallel, and is a direct
  6. indicator of perceived performance due to noisy neighbours. In order to keep
  7. the value low, it is possible to reduce the scheduler's run queue depth using
  8. "tune.runqueue-depth", to reduce the number of concurrent events processed at
  9. once using "tune.maxpollevents", to decrease the stream's nice value using
  10. the "nice" option on the "bind" lines or in the frontend, or to look for
  11. other heavy requests in logs (those exhibiting large values of "cpu_ns_avg"),
  12. whose processing needs to be adjusted or fixed. Compression of large buffers
  13. could be a culprit, like heavy regex or long lists of regex.
  14. Note: this value is exactly lat_ns_tot divided by cpu_calls.

lat_ns_tot : integer

  1. Returns the total number of nanoseconds spent between the moment the task
  2. handling the stream is woken up and the moment it is effectively called. This
  3. number is reset for each new request on the same connections in case of HTTP
  4. keep-alive. This value indicates the overall latency inflicted to the current
  5. request by all other requests being processed in parallel, and is a direct
  6. indicator of perceived performance due to noisy neighbours. In order to keep
  7. the value low, it is possible to reduce the scheduler's run queue depth using
  8. "tune.runqueue-depth", to reduce the number of concurrent events processed at
  9. once using "tune.maxpollevents", to decrease the stream's nice value using
  10. the "nice" option on the "bind" lines or in the frontend, or to look for
  11. other heavy requests in logs (those exhibiting large values of "cpu_ns_avg"),
  12. whose processing needs to be adjusted or fixed. Compression of large buffers
  13. could be a culprit, like heavy regex or long lists of regex. Note: while it
  14. may intuitively seem that the total latency adds to a transfer time, it is
  15. almost never true because while a task waits for the CPU, network buffers
  16. continue to fill up and the next call will process more at once. The value
  17. may be artificially high due to a high cpu_calls count, for example when
  18. processing many HTTP chunks, and for this reason it is often preferred to log
  19. lat_ns_avg instead, which is a more relevant performance indicator.

meth() : method

  1. Returns a method.

nbproc : integer

  1. Returns an integer value corresponding to the number of processes that were
  2. started (it equals the global "nbproc" setting). This is useful for logging
  3. and debugging purposes.

nbsrv([]) : integer

  1. Returns an integer value corresponding to the number of usable servers of
  2. either the current backend or the named backend. This is mostly used with
  3. ACLs but can also be useful when added to logs. This is normally used to
  4. switch to an alternate backend when the number of servers is too low to
  5. to handle some load. It is useful to report a failure when combined with
  6. "monitor fail".

prio_class : integer

  1. Returns the priority class of the current session for http mode or connection
  2. for tcp mode. The value will be that set by the last call to "http-request
  3. set-priority-class" or "tcp-request content set-priority-class".

prio_offset : integer

  1. Returns the priority offset of the current session for http mode or
  2. connection for tcp mode. The value will be that set by the last call to
  3. "http-request set-priority-offset" or "tcp-request content
  4. set-priority-offset".

proc : integer

  1. Returns an integer value corresponding to the position of the process calling
  2. the function, between 1 and global.nbproc. This is useful for logging and
  3. debugging purposes.

queue([]) : integer

  1. Returns the total number of queued connections of the designated backend,
  2. including all the connections in server queues. If no backend name is
  3. specified, the current one is used, but it is also possible to check another
  4. one. This is useful with ACLs or to pass statistics to backend servers. This
  5. can be used to take actions when queuing goes above a known level, generally
  6. indicating a surge of traffic or a massive slowdown on the servers. One
  7. possible action could be to reject new users but still accept old ones. See
  8. also the "avg_queue", "be_conn", and "be_sess_rate" fetches.

rand([]) : integer

  1. Returns a random integer value within a range of <range> possible values,
  2. starting at zero. If the range is not specified, it defaults to 2^32, which
  3. gives numbers between 0 and 4294967295. It can be useful to pass some values
  4. needed to take some routing decisions for example, or just for debugging
  5. purposes. This random must not be used for security purposes.

uuid([]) : string

  1. Returns a UUID following the RFC4122 standard. If the version is not
  2. specified, a UUID version 4 (fully random) is returned.
  3. Currently, only version 4 is supported.

srv_conn([/]) : integer

  1. Returns an integer value corresponding to the number of currently established
  2. connections on the designated server, possibly including the connection being
  3. evaluated. If <backend> is omitted, then the server is looked up in the
  4. current backend. It can be used to use a specific farm when one server is
  5. full, or to inform the server about our view of the number of active
  6. connections with it. See also the "fe_conn", "be_conn", "queue", and
  7. "srv_conn_free" fetch methods.

srv_conn_free([/]) : integer

  1. Returns an integer value corresponding to the number of available connections
  2. on the designated server, possibly including the connection being evaluated.
  3. The value does not include queue slots. If <backend> is omitted, then the
  4. server is looked up in the current backend. It can be used to use a specific
  5. farm when one server is full, or to inform the server about our view of the
  6. number of active connections with it. See also the "be_conn_free" and
  7. "srv_conn" fetch methods.
  8.  
  9. OTHER CAVEATS AND NOTES: If the server maxconn is 0, then this fetch clearly
  10. does not make sense, in which case the value returned will be -1.

srv_is_up([/]) : boolean

  1. Returns true when the designated server is UP, and false when it is either
  2. DOWN or in maintenance mode. If <backend> is omitted, then the server is
  3. looked up in the current backend. It is mainly used to take action based on
  4. an external status reported via a health check (e.g. a geographical site's
  5. availability). Another possible use which is more of a hack consists in
  6. using dummy servers as boolean variables that can be enabled or disabled from
  7. the CLI, so that rules depending on those ACLs can be tweaked in realtime.

srv_queue([/]) : integer

  1. Returns an integer value corresponding to the number of connections currently
  2. pending in the designated server's queue. If <backend> is omitted, then the
  3. server is looked up in the current backend. It can sometimes be used together
  4. with the "use-server" directive to force to use a known faster server when it
  5. is not much loaded. See also the "srv_conn", "avg_queue" and "queue" sample
  6. fetch methods.

srv_sess_rate([/]) : integer

  1. Returns an integer corresponding to the sessions creation rate on the
  2. designated server, in number of new sessions per second. If <backend> is
  3. omitted, then the server is looked up in the current backend. This is mostly
  4. used with ACLs but can make sense with logs too. This is used to switch to an
  5. alternate backend when an expensive or fragile one reaches too high a session
  6. rate, or to limit abuse of service (e.g. prevent latent requests from
  7. overloading servers).

Example :

  1. # Redirect to a separate back
  2. acl srv1_full srv_sess_rate(be1/srv1) gt 50
  3. acl srv2_full srv_sess_rate(be1/srv2) gt 50
  4. use_backend be2 if srv1_full or srv2_full

stopping : boolean

  1. Returns TRUE if the process calling the function is currently stopping. This
  2. can be useful for logging, or for relaxing certain checks or helping close
  3. certain connections upon graceful shutdown.

str() : string

  1. Returns a string.

table_avl([

]) : integer

  1. Returns the total number of available entries in the current proxy's
  2. stick-table or in the designated stick-table. See also table_cnt.

table_cnt([

]) : integer

  1. Returns the total number of entries currently in use in the current proxy's
  2. stick-table or in the designated stick-table. See also src_conn_cnt and
  3. table_avl for other entry counting methods.

thread : integer

  1. Returns an integer value corresponding to the position of the thread calling
  2. the function, between 0 and (global.nbthread-1). This is useful for logging
  3. and debugging purposes.

var() : undefined

  1. Returns a variable with the stored type. If the variable is not set, the
  2. sample fetch fails. The name of the variable starts with an indication
  3. about its scope. The scopes allowed are:
  4. "proc" : the variable is shared with the whole process
  5. "sess" : the variable is shared with the whole session
  6. "txn" : the variable is shared with the transaction (request and
  7. response),
  8. "req" : the variable is shared only during request processing,
  9. "res" : the variable is shared only during response processing.
  10. This prefix is followed by a name. The separator is a '.'. The name may only
  11. contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.

7.3.3. Fetching samples at Layer 4

  1. The layer 4 usually describes just the transport layer which in haproxy is
  2. closest to the connection, where no content is yet made available. The fetch
  3. methods described here are usable as low as the "tcp-request connection" rule
  4. sets unless they require some future information. Those generally include
  5. TCP/IP addresses and ports, as well as elements from stick-tables related to
  6. the incoming connection. For retrieving a value from a sticky counters, the
  7. counter number can be explicitly set as 0, 1, or 2 using the pre-defined
  8. "sc0_", "sc1_", or "sc2_" prefix. These three pre-defined prefixes can only be
  9. used if MAX_SESS_STKCTR value does not exceed 3, otherwise the counter number
  10. can be specified as the first integer argument when using the "sc_" prefix.
  11. Starting from "sc_0" to "sc_N" where N is (MAX_SESS_STKCTR-1). An optional
  12. table may be specified with the "sc*" form, in which case the currently
  13. tracked key will be looked up into this alternate table instead of the table
  14. currently being tracked.

bc_http_major : integer

  1. Returns the backend connection's HTTP major version encoding, which may be 1
  2. for HTTP/0.9 to HTTP/1.1 or 2 for HTTP/2. Note, this is based on the on-wire
  3. encoding and not the version present in the request header.

be_id : integer

  1. Returns an integer containing the current backend's id. It can be used in
  2. frontends with responses to check which backend processed the request.

be_name : string

  1. Returns a string containing the current backend's name. It can be used in
  2. frontends with responses to check which backend processed the request.

dst : ip

  1. This is the destination IPv4 address of the connection on the client side,
  2. which is the address the client connected to. It can be useful when running
  3. in transparent mode. It is of type IP and works on both IPv4 and IPv6 tables.
  4. On IPv6 tables, IPv4 address is mapped to its IPv6 equivalent, according to
  5. RFC 4291. When the incoming connection passed through address translation or
  6. redirection involving connection tracking, the original destination address
  7. before the redirection will be reported. On Linux systems, the source and
  8. destination may seldom appear reversed if the nf_conntrack_tcp_loose sysctl
  9. is set, because a late response may reopen a timed out connection and switch
  10. what is believed to be the source and the destination.

dst_conn : integer

  1. Returns an integer value corresponding to the number of currently established
  2. connections on the same socket including the one being evaluated. It is
  3. normally used with ACLs but can as well be used to pass the information to
  4. servers in an HTTP header or in logs. It can be used to either return a sorry
  5. page before hard-blocking, or to use a specific backend to drain new requests
  6. when the socket is considered saturated. This offers the ability to assign
  7. different limits to different listening ports or addresses. See also the
  8. "fe_conn" and "be_conn" fetches.

dst_is_local : boolean

  1. Returns true if the destination address of the incoming connection is local
  2. to the system, or false if the address doesn't exist on the system, meaning
  3. that it was intercepted in transparent mode. It can be useful to apply
  4. certain rules by default to forwarded traffic and other rules to the traffic
  5. targeting the real address of the machine. For example the stats page could
  6. be delivered only on this address, or SSH access could be locally redirected.
  7. Please note that the check involves a few system calls, so it's better to do
  8. it only once per connection.

dst_port : integer

  1. Returns an integer value corresponding to the destination TCP port of the
  2. connection on the client side, which is the port the client connected to.
  3. This might be used when running in transparent mode, when assigning dynamic
  4. ports to some clients for a whole application session, to stick all users to
  5. a same server, or to pass the destination port information to a server using
  6. an HTTP header.

fc_http_major : integer

  1. Reports the front connection's HTTP major version encoding, which may be 1
  2. for HTTP/0.9 to HTTP/1.1 or 2 for HTTP/2. Note, this is based on the on-wire
  3. encoding and not on the version present in the request header.

fc_rcvd_proxy : boolean

  1. Returns true if the client initiated the connection with a PROXY protocol
  2. header.

fc_rtt() : integer

  1. Returns the Round Trip Time (RTT) measured by the kernel for the client
  2. connection. <unit> is facultative, by default the unit is milliseconds. <unit>
  3. can be set to "ms" for milliseconds or "us" for microseconds. If the server
  4. connection is not established, if the connection is not TCP or if the
  5. operating system does not support TCP_INFO, for example Linux kernels before
  6. 2.4, the sample fetch fails.

fc_rttvar() : integer

  1. Returns the Round Trip Time (RTT) variance measured by the kernel for the
  2. client connection. <unit> is facultative, by default the unit is milliseconds.
  3. <unit> can be set to "ms" for milliseconds or "us" for microseconds. If the
  4. server connection is not established, if the connection is not TCP or if the
  5. operating system does not support TCP_INFO, for example Linux kernels before
  6. 2.4, the sample fetch fails.

fc_unacked : integer

  1. Returns the unacked counter measured by the kernel for the client connection.
  2. If the server connection is not established, if the connection is not TCP or
  3. if the operating system does not support TCP_INFO, for example Linux kernels
  4. before 2.4, the sample fetch fails.

fc_sacked : integer

  1. Returns the sacked counter measured by the kernel for the client connection.
  2. If the server connection is not established, if the connection is not TCP or
  3. if the operating system does not support TCP_INFO, for example Linux kernels
  4. before 2.4, the sample fetch fails.

fc_retrans : integer

  1. Returns the retransmits counter measured by the kernel for the client
  2. connection. If the server connection is not established, if the connection is
  3. not TCP or if the operating system does not support TCP_INFO, for example
  4. Linux kernels before 2.4, the sample fetch fails.

fc_fackets : integer

  1. Returns the fack counter measured by the kernel for the client
  2. connection. If the server connection is not established, if the connection is
  3. not TCP or if the operating system does not support TCP_INFO, for example
  4. Linux kernels before 2.4, the sample fetch fails.

fc_lost : integer

  1. Returns the lost counter measured by the kernel for the client
  2. connection. If the server connection is not established, if the connection is
  3. not TCP or if the operating system does not support TCP_INFO, for example
  4. Linux kernels before 2.4, the sample fetch fails.

fc_reordering : integer

  1. Returns the reordering counter measured by the kernel for the client
  2. connection. If the server connection is not established, if the connection is
  3. not TCP or if the operating system does not support TCP_INFO, for example
  4. Linux kernels before 2.4, the sample fetch fails.

fe_defbe : string

  1. Returns a string containing the frontend's default backend name. It can be
  2. used in frontends to check which backend will handle requests by default.

fe_id : integer

  1. Returns an integer containing the current frontend's id. It can be used in
  2. backends to check from which frontend it was called, or to stick all users
  3. coming via a same frontend to the same server.

fe_name : string

  1. Returns a string containing the current frontend's name. It can be used in
  2. backends to check from which frontend it was called, or to stick all users
  3. coming via a same frontend to the same server.

sc_bytes_in_rate([,

]) : integer

sc0_bytes_in_rate([

]) : integer

sc1_bytes_in_rate([

]) : integer

sc2_bytes_in_rate([

]) : integer

  1. Returns the average client-to-server bytes rate from the currently tracked
  2. counters, measured in amount of bytes over the period configured in the
  3. table. See also src_bytes_in_rate.

sc_bytes_out_rate([,

]) : integer

sc0_bytes_out_rate([

]) : integer

sc1_bytes_out_rate([

]) : integer

sc2_bytes_out_rate([

]) : integer

  1. Returns the average server-to-client bytes rate from the currently tracked
  2. counters, measured in amount of bytes over the period configured in the
  3. table. See also src_bytes_out_rate.

sc_clr_gpc0([,

]) : integer

sc0_clr_gpc0([

]) : integer

sc1_clr_gpc0([

]) : integer

sc2_clr_gpc0([

]) : integer

  1. Clears the first General Purpose Counter associated to the currently tracked
  2. counters, and returns its previous value. Before the first invocation, the
  3. stored value is zero, so first invocation will always return zero. This is
  4. typically used as a second ACL in an expression in order to mark a connection
  5. when a first ACL was verified :

Example:

  1. # block if 5 consecutive requests continue to come faster than 10 sess
  2. # per second, and reset the counter as soon as the traffic slows down.
  3. acl abuse sc0_http_req_rate gt 10
  4. acl kill sc0_inc_gpc0 gt 5
  5. acl save sc0_clr_gpc0 ge 0
  6. tcp-request connection accept if !abuse save
  7. tcp-request connection reject if abuse kill

sc_clr_gpc1([,

]) : integer

sc0_clr_gpc1([

]) : integer

sc1_clr_gpc1([

]) : integer

sc2_clr_gpc1([

]) : integer

  1. Clears the second General Purpose Counter associated to the currently tracked
  2. counters, and returns its previous value. Before the first invocation, the
  3. stored value is zero, so first invocation will always return zero. This is
  4. typically used as a second ACL in an expression in order to mark a connection
  5. when a first ACL was verified.

sc_conn_cnt([,

]) : integer

sc0_conn_cnt([

]) : integer

sc1_conn_cnt([

]) : integer

sc2_conn_cnt([

]) : integer

  1. Returns the cumulative number of incoming connections from currently tracked
  2. counters. See also src_conn_cnt.

sc_conn_cur([,

]) : integer

sc0_conn_cur([

]) : integer

sc1_conn_cur([

]) : integer

sc2_conn_cur([

]) : integer

  1. Returns the current amount of concurrent connections tracking the same
  2. tracked counters. This number is automatically incremented when tracking
  3. begins and decremented when tracking stops. See also src_conn_cur.

sc_conn_rate([,

]) : integer

sc0_conn_rate([

]) : integer

sc1_conn_rate([

]) : integer

sc2_conn_rate([

]) : integer

  1. Returns the average connection rate from the currently tracked counters,
  2. measured in amount of connections over the period configured in the table.
  3. See also src_conn_rate.

sc_get_gpc0([,

]) : integer

sc0_get_gpc0([

]) : integer

sc1_get_gpc0([

]) : integer

sc2_get_gpc0([

]) : integer

  1. Returns the value of the first General Purpose Counter associated to the
  2. currently tracked counters. See also src_get_gpc0 and sc/sc0/sc1/sc2_inc_gpc0.

sc_get_gpc1([,

]) : integer

sc0_get_gpc1([

]) : integer

sc1_get_gpc1([

]) : integer

sc2_get_gpc1([

]) : integer

  1. Returns the value of the second General Purpose Counter associated to the
  2. currently tracked counters. See also src_get_gpc1 and sc/sc0/sc1/sc2_inc_gpc1.

sc_get_gpt0([,

]) : integer

sc0_get_gpt0([

]) : integer

sc1_get_gpt0([

]) : integer

sc2_get_gpt0([

]) : integer

  1. Returns the value of the first General Purpose Tag associated to the
  2. currently tracked counters. See also src_get_gpt0.

sc_gpc0_rate([,

]) : integer

sc0_gpc0_rate([

]) : integer

sc1_gpc0_rate([

]) : integer

sc2_gpc0_rate([

]) : integer

  1. Returns the average increment rate of the first General Purpose Counter
  2. associated to the currently tracked counters. It reports the frequency
  3. which the gpc0 counter was incremented over the configured period. See also
  4. src_gpc0_rate, sc/sc0/sc1/sc2_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
  5. that the "gpc0_rate" counter must be stored in the stick-table for a value to
  6. be returned, as "gpc0" only holds the event count.

sc_gpc1_rate([,

]) : integer

sc0_gpc1_rate([

]) : integer

sc1_gpc1_rate([

]) : integer

sc2_gpc1_rate([

]) : integer

  1. Returns the average increment rate of the second General Purpose Counter
  2. associated to the currently tracked counters. It reports the frequency
  3. which the gpc1 counter was incremented over the configured period. See also
  4. src_gpcA_rate, sc/sc0/sc1/sc2_get_gpc1, and sc/sc0/sc1/sc2_inc_gpc1. Note
  5. that the "gpc1_rate" counter must be stored in the stick-table for a value to
  6. be returned, as "gpc1" only holds the event count.

sc_http_err_cnt([,

]) : integer

sc0_http_err_cnt([

]) : integer

sc1_http_err_cnt([

]) : integer

sc2_http_err_cnt([

]) : integer

  1. Returns the cumulative number of HTTP errors from the currently tracked
  2. counters. This includes the both request errors and 4xx error responses.
  3. See also src_http_err_cnt.

sc_http_err_rate([,

]) : integer

sc0_http_err_rate([

]) : integer

sc1_http_err_rate([

]) : integer

sc2_http_err_rate([

]) : integer

  1. Returns the average rate of HTTP errors from the currently tracked counters,
  2. measured in amount of errors over the period configured in the table. This
  3. includes the both request errors and 4xx error responses. See also
  4. src_http_err_rate.

sc_http_req_cnt([,

]) : integer

sc0_http_req_cnt([

]) : integer

sc1_http_req_cnt([

]) : integer

sc2_http_req_cnt([

]) : integer

  1. Returns the cumulative number of HTTP requests from the currently tracked
  2. counters. This includes every started request, valid or not. See also
  3. src_http_req_cnt.

sc_http_req_rate([,

]) : integer

sc0_http_req_rate([

]) : integer

sc1_http_req_rate([

]) : integer

sc2_http_req_rate([

]) : integer

  1. Returns the average rate of HTTP requests from the currently tracked
  2. counters, measured in amount of requests over the period configured in
  3. the table. This includes every started request, valid or not. See also
  4. src_http_req_rate.

sc_inc_gpc0([,

]) : integer

sc0_inc_gpc0([

]) : integer

sc1_inc_gpc0([

]) : integer

sc2_inc_gpc0([

]) : integer

  1. Increments the first General Purpose Counter associated to the currently
  2. tracked counters, and returns its new value. Before the first invocation,
  3. the stored value is zero, so first invocation will increase it to 1 and will
  4. return 1. This is typically used as a second ACL in an expression in order
  5. to mark a connection when a first ACL was verified :

Example:

  1. acl abuse sc0_http_req_rate gt 10
  2. acl kill sc0_inc_gpc0 gt 0
  3. tcp-request connection reject if abuse kill

sc_inc_gpc1([,

]) : integer

sc0_inc_gpc1([

]) : integer

sc1_inc_gpc1([

]) : integer

sc2_inc_gpc1([

]) : integer

  1. Increments the second General Purpose Counter associated to the currently
  2. tracked counters, and returns its new value. Before the first invocation,
  3. the stored value is zero, so first invocation will increase it to 1 and will
  4. return 1. This is typically used as a second ACL in an expression in order
  5. to mark a connection when a first ACL was verified.

sc_kbytes_in([,

]) : integer

sc0_kbytes_in([

]) : integer

sc1_kbytes_in([

]) : integer

sc2_kbytes_in([

]) : integer

  1. Returns the total amount of client-to-server data from the currently tracked
  2. counters, measured in kilobytes. The test is currently performed on 32-bit
  3. integers, which limits values to 4 terabytes. See also src_kbytes_in.

sc_kbytes_out([,

]) : integer

sc0_kbytes_out([

]) : integer

sc1_kbytes_out([

]) : integer

sc2_kbytes_out([

]) : integer

  1. Returns the total amount of server-to-client data from the currently tracked
  2. counters, measured in kilobytes. The test is currently performed on 32-bit
  3. integers, which limits values to 4 terabytes. See also src_kbytes_out.

sc_sess_cnt([,

]) : integer

sc0_sess_cnt([

]) : integer

sc1_sess_cnt([

]) : integer

sc2_sess_cnt([

]) : integer

  1. Returns the cumulative number of incoming connections that were transformed
  2. into sessions, which means that they were accepted by a "tcp-request
  3. connection" rule, from the currently tracked counters. A backend may count
  4. more sessions than connections because each connection could result in many
  5. backend sessions if some HTTP keep-alive is performed over the connection
  6. with the client. See also src_sess_cnt.

sc_sess_rate([,

]) : integer

sc0_sess_rate([

]) : integer

sc1_sess_rate([

]) : integer

sc2_sess_rate([

]) : integer

  1. Returns the average session rate from the currently tracked counters,
  2. measured in amount of sessions over the period configured in the table. A
  3. session is a connection that got past the early "tcp-request connection"
  4. rules. A backend may count more sessions than connections because each
  5. connection could result in many backend sessions if some HTTP keep-alive is
  6. performed over the connection with the client. See also src_sess_rate.

sc_tracked([,

]) : boolean

sc0_tracked([

]) : boolean

sc1_tracked([

]) : boolean

sc2_tracked([

]) : boolean

  1. Returns true if the designated session counter is currently being tracked by
  2. the current session. This can be useful when deciding whether or not we want
  3. to set some values in a header passed to the server.

sc_trackers([,

]) : integer

sc0_trackers([

]) : integer

sc1_trackers([

]) : integer

sc2_trackers([

]) : integer

  1. Returns the current amount of concurrent connections tracking the same
  2. tracked counters. This number is automatically incremented when tracking
  3. begins and decremented when tracking stops. It differs from sc0_conn_cur in
  4. that it does not rely on any stored information but on the table's reference
  5. count (the "use" value which is returned by "show table" on the CLI). This
  6. may sometimes be more suited for layer7 tracking. It can be used to tell a
  7. server how many concurrent connections there are from a given address for
  8. example.

so_id : integer

  1. Returns an integer containing the current listening socket's id. It is useful
  2. in frontends involving many "bind" lines, or to stick all users coming via a
  3. same socket to the same server.

so_name : string

  1. Returns a string containing the current listening socket's name, as defined
  2. with name on a "bind" line. It can serve the same purposes as so_id but with
  3. strings instead of integers.

src : ip

  1. This is the source IPv4 address of the client of the session. It is of type
  2. IP and works on both IPv4 and IPv6 tables. On IPv6 tables, IPv4 addresses are
  3. mapped to their IPv6 equivalent, according to RFC 4291. Note that it is the
  4. TCP-level source address which is used, and not the address of a client
  5. behind a proxy. However if the "accept-proxy" or "accept-netscaler-cip" bind
  6. directive is used, it can be the address of a client behind another
  7. PROXY-protocol compatible component for all rule sets except
  8. "tcp-request connection" which sees the real address. When the incoming
  9. connection passed through address translation or redirection involving
  10. connection tracking, the original destination address before the redirection
  11. will be reported. On Linux systems, the source and destination may seldom
  12. appear reversed if the nf_conntrack_tcp_loose sysctl is set, because a late
  13. response may reopen a timed out connection and switch what is believed to be
  14. the source and the destination.

Example:

  1. # add an HTTP header in requests with the originating address' country
  2. http-request set-header X-Country %[src,map_ip(geoip.lst)]

src_bytes_in_rate([

]) : integer

  1. Returns the average bytes rate from the incoming connection's source address
  2. in the current proxy's stick-table or in the designated stick-table, measured
  3. in amount of bytes over the period configured in the table. If the address is
  4. not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_in_rate.

src_bytes_out_rate([

]) : integer

  1. Returns the average bytes rate to the incoming connection's source address in
  2. the current proxy's stick-table or in the designated stick-table, measured in
  3. amount of bytes over the period configured in the table. If the address is
  4. not found, zero is returned. See also sc/sc0/sc1/sc2_bytes_out_rate.

src_clr_gpc0([

]) : integer

  1. Clears the first General Purpose Counter associated to the incoming
  2. connection's source address in the current proxy's stick-table or in the
  3. designated stick-table, and returns its previous value. If the address is not
  4. found, an entry is created and 0 is returned. This is typically used as a
  5. second ACL in an expression in order to mark a connection when a first ACL
  6. was verified :

Example:

  1. # block if 5 consecutive requests continue to come faster than 10 sess
  2. # per second, and reset the counter as soon as the traffic slows down.
  3. acl abuse src_http_req_rate gt 10
  4. acl kill src_inc_gpc0 gt 5
  5. acl save src_clr_gpc0 ge 0
  6. tcp-request connection accept if !abuse save
  7. tcp-request connection reject if abuse kill

src_clr_gpc1([

]) : integer

  1. Clears the second General Purpose Counter associated to the incoming
  2. connection's source address in the current proxy's stick-table or in the
  3. designated stick-table, and returns its previous value. If the address is not
  4. found, an entry is created and 0 is returned. This is typically used as a
  5. second ACL in an expression in order to mark a connection when a first ACL
  6. was verified.

src_conn_cnt([

]) : integer

  1. Returns the cumulative number of connections initiated from the current
  2. incoming connection's source address in the current proxy's stick-table or in
  3. the designated stick-table. If the address is not found, zero is returned.
  4. See also sc/sc0/sc1/sc2_conn_cnt.

src_conn_cur([

]) : integer

  1. Returns the current amount of concurrent connections initiated from the
  2. current incoming connection's source address in the current proxy's
  3. stick-table or in the designated stick-table. If the address is not found,
  4. zero is returned. See also sc/sc0/sc1/sc2_conn_cur.

src_conn_rate([

]) : integer

  1. Returns the average connection rate from the incoming connection's source
  2. address in the current proxy's stick-table or in the designated stick-table,
  3. measured in amount of connections over the period configured in the table. If
  4. the address is not found, zero is returned. See also sc/sc0/sc1/sc2_conn_rate.

src_get_gpc0([

]) : integer

  1. Returns the value of the first General Purpose Counter associated to the
  2. incoming connection's source address in the current proxy's stick-table or in
  3. the designated stick-table. If the address is not found, zero is returned.
  4. See also sc/sc0/sc1/sc2_get_gpc0 and src_inc_gpc0.

src_get_gpc1([

]) : integer

  1. Returns the value of the second General Purpose Counter associated to the
  2. incoming connection's source address in the current proxy's stick-table or in
  3. the designated stick-table. If the address is not found, zero is returned.
  4. See also sc/sc0/sc1/sc2_get_gpc1 and src_inc_gpc1.

src_get_gpt0([

]) : integer

  1. Returns the value of the first General Purpose Tag associated to the
  2. incoming connection's source address in the current proxy's stick-table or in
  3. the designated stick-table. If the address is not found, zero is returned.
  4. See also sc/sc0/sc1/sc2_get_gpt0.

src_gpc0_rate([

]) : integer

  1. Returns the average increment rate of the first General Purpose Counter
  2. associated to the incoming connection's source address in the current proxy's
  3. stick-table or in the designated stick-table. It reports the frequency
  4. which the gpc0 counter was incremented over the configured period. See also
  5. sc/sc0/sc1/sc2_gpc0_rate, src_get_gpc0, and sc/sc0/sc1/sc2_inc_gpc0. Note
  6. that the "gpc0_rate" counter must be stored in the stick-table for a value to
  7. be returned, as "gpc0" only holds the event count.

src_gpc1_rate([

]) : integer

  1. Returns the average increment rate of the second General Purpose Counter
  2. associated to the incoming connection's source address in the current proxy's
  3. stick-table or in the designated stick-table. It reports the frequency
  4. which the gpc1 counter was incremented over the configured period. See also
  5. sc/sc0/sc1/sc2_gpc1_rate, src_get_gpc1, and sc/sc0/sc1/sc2_inc_gpc1. Note
  6. that the "gpc1_rate" counter must be stored in the stick-table for a value to
  7. be returned, as "gpc1" only holds the event count.

src_http_err_cnt([

]) : integer

  1. Returns the cumulative number of HTTP errors from the incoming connection's
  2. source address in the current proxy's stick-table or in the designated
  3. stick-table. This includes the both request errors and 4xx error responses.
  4. See also sc/sc0/sc1/sc2_http_err_cnt. If the address is not found, zero is
  5. returned.

src_http_err_rate([

]) : integer

  1. Returns the average rate of HTTP errors from the incoming connection's source
  2. address in the current proxy's stick-table or in the designated stick-table,
  3. measured in amount of errors over the period configured in the table. This
  4. includes the both request errors and 4xx error responses. If the address is
  5. not found, zero is returned. See also sc/sc0/sc1/sc2_http_err_rate.

src_http_req_cnt([

]) : integer

  1. Returns the cumulative number of HTTP requests from the incoming connection's
  2. source address in the current proxy's stick-table or in the designated stick-
  3. table. This includes every started request, valid or not. If the address is
  4. not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_cnt.

src_http_req_rate([

]) : integer

  1. Returns the average rate of HTTP requests from the incoming connection's
  2. source address in the current proxy's stick-table or in the designated stick-
  3. table, measured in amount of requests over the period configured in the
  4. table. This includes every started request, valid or not. If the address is
  5. not found, zero is returned. See also sc/sc0/sc1/sc2_http_req_rate.

src_inc_gpc0([

]) : integer

  1. Increments the first General Purpose Counter associated to the incoming
  2. connection's source address in the current proxy's stick-table or in the
  3. designated stick-table, and returns its new value. If the address is not
  4. found, an entry is created and 1 is returned. See also sc0/sc2/sc2_inc_gpc0.
  5. This is typically used as a second ACL in an expression in order to mark a
  6. connection when a first ACL was verified :

Example:

  1. acl abuse src_http_req_rate gt 10
  2. acl kill src_inc_gpc0 gt 0
  3. tcp-request connection reject if abuse kill

src_inc_gpc1([

]) : integer

  1. Increments the second General Purpose Counter associated to the incoming
  2. connection's source address in the current proxy's stick-table or in the
  3. designated stick-table, and returns its new value. If the address is not
  4. found, an entry is created and 1 is returned. See also sc0/sc2/sc2_inc_gpc1.
  5. This is typically used as a second ACL in an expression in order to mark a
  6. connection when a first ACL was verified.

src_is_local : boolean

  1. Returns true if the source address of the incoming connection is local to the
  2. system, or false if the address doesn't exist on the system, meaning that it
  3. comes from a remote machine. Note that UNIX addresses are considered local.
  4. It can be useful to apply certain access restrictions based on where the
  5. client comes from (e.g. require auth or https for remote machines). Please
  6. note that the check involves a few system calls, so it's better to do it only
  7. once per connection.

src_kbytes_in([

]) : integer

  1. Returns the total amount of data received from the incoming connection's
  2. source address in the current proxy's stick-table or in the designated
  3. stick-table, measured in kilobytes. If the address is not found, zero is
  4. returned. The test is currently performed on 32-bit integers, which limits
  5. values to 4 terabytes. See also sc/sc0/sc1/sc2_kbytes_in.

src_kbytes_out([

]) : integer

  1. Returns the total amount of data sent to the incoming connection's source
  2. address in the current proxy's stick-table or in the designated stick-table,
  3. measured in kilobytes. If the address is not found, zero is returned. The
  4. test is currently performed on 32-bit integers, which limits values to 4
  5. terabytes. See also sc/sc0/sc1/sc2_kbytes_out.

src_port : integer

  1. Returns an integer value corresponding to the TCP source port of the
  2. connection on the client side, which is the port the client connected from.
  3. Usage of this function is very limited as modern protocols do not care much
  4. about source ports nowadays.

src_sess_cnt([

]) : integer

  1. Returns the cumulative number of connections initiated from the incoming
  2. connection's source IPv4 address in the current proxy's stick-table or in the
  3. designated stick-table, that were transformed into sessions, which means that
  4. they were accepted by "tcp-request" rules. If the address is not found, zero
  5. is returned. See also sc/sc0/sc1/sc2_sess_cnt.

src_sess_rate([

]) : integer

  1. Returns the average session rate from the incoming connection's source
  2. address in the current proxy's stick-table or in the designated stick-table,
  3. measured in amount of sessions over the period configured in the table. A
  4. session is a connection that went past the early "tcp-request" rules. If the
  5. address is not found, zero is returned. See also sc/sc0/sc1/sc2_sess_rate.

src_updt_conn_cnt([

]) : integer

  1. Creates or updates the entry associated to the incoming connection's source
  2. address in the current proxy's stick-table or in the designated stick-table.
  3. This table must be configured to store the "conn_cnt" data type, otherwise
  4. the match will be ignored. The current count is incremented by one, and the
  5. expiration timer refreshed. The updated count is returned, so this match
  6. can't return zero. This was used to reject service abusers based on their
  7. source address. Note: it is recommended to use the more complete "track-sc*"
  8. actions in "tcp-request" rules instead.

Example :

  1. # This frontend limits incoming SSH connections to 3 per 10 second for
  2. # each source address, and rejects excess connections until a 10 second
  3. # silence is observed. At most 20 addresses are tracked.
  4. listen ssh
  5. bind :22
  6. mode tcp
  7. maxconn 100
  8. stick-table type ip size 20 expire 10s store conn_cnt
  9. tcp-request content reject if { src_updt_conn_cnt gt 3 }
  10. server local 127.0.0.1:22

srv_id : integer

  1. Returns an integer containing the server's id when processing the response.
  2. While it's almost only used with ACLs, it may be used for logging or
  3. debugging.

7.3.4. Fetching samples at Layer 5

  1. The layer 5 usually describes just the session layer which in haproxy is
  2. closest to the session once all the connection handshakes are finished, but
  3. when no content is yet made available. The fetch methods described here are
  4. usable as low as the "tcp-request content" rule sets unless they require some
  5. future information. Those generally include the results of SSL negotiations.

51d.all([,*]) : string

  1. Returns values for the properties requested as a string, where values are
  2. separated by the delimiter specified with "51degrees-property-separator".
  3. The device is identified using all the important HTTP headers from the
  4. request. The function can be passed up to five property names, and if a
  5. property name can't be found, the value "NoData" is returned.

Example :

  1. # Here the header "X-51D-DeviceTypeMobileTablet" is added to the request
  2. # containing the three properties requested using all relevant headers from
  3. # the request.
  4. frontend http-in
  5. bind *:8081
  6. default_backend servers
  7. http-request set-header X-51D-DeviceTypeMobileTablet \
  8. %[51d.all(DeviceType,IsMobile,IsTablet)]

ssl_bc : boolean

  1. Returns true when the back connection was made via an SSL/TLS transport
  2. layer and is locally deciphered. This means the outgoing connection was made
  3. other a server with the "ssl" option.

ssl_bc_alg_keysize : integer

  1. Returns the symmetric cipher key size supported in bits when the outgoing
  2. connection was made over an SSL/TLS transport layer.

ssl_bc_alpn : string

  1. This extracts the Application Layer Protocol Negotiation field from an
  2. outgoing connection made via a TLS transport layer.
  3. The result is a string containing the protocol name negotiated with the
  4. server. The SSL library must have been built with support for TLS
  5. extensions enabled (check haproxy -vv). Note that the TLS ALPN extension is
  6. not advertised unless the "alpn" keyword on the "server" line specifies a
  7. protocol list. Also, nothing forces the server to pick a protocol from this
  8. list, any other one may be requested. The TLS ALPN extension is meant to
  9. replace the TLS NPN extension. See also "ssl_bc_npn".

ssl_bc_cipher : string

  1. Returns the name of the used cipher when the outgoing connection was made
  2. over an SSL/TLS transport layer.

ssl_bc_client_random : binary

  1. Returns the client random of the back connection when the incoming connection
  2. was made over an SSL/TLS transport layer. It is useful to to decrypt traffic
  3. sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or BoringSSL.

ssl_bc_is_resumed : boolean

  1. Returns true when the back connection was made over an SSL/TLS transport
  2. layer and the newly created SSL session was resumed using a cached
  3. session or a TLS ticket.

ssl_bc_npn : string

  1. This extracts the Next Protocol Negotiation field from an outgoing connection
  2. made via a TLS transport layer. The result is a string containing the
  3. protocol name negotiated with the server . The SSL library must have been
  4. built with support for TLS extensions enabled (check haproxy -vv). Note that
  5. the TLS NPN extension is not advertised unless the "npn" keyword on the
  6. "server" line specifies a protocol list. Also, nothing forces the server to
  7. pick a protocol from this list, any other one may be used. Please note that
  8. the TLS NPN extension was replaced with ALPN.

ssl_bc_protocol : string

  1. Returns the name of the used protocol when the outgoing connection was made
  2. over an SSL/TLS transport layer.

ssl_bc_unique_id : binary

  1. When the outgoing connection was made over an SSL/TLS transport layer,
  2. returns the TLS unique ID as defined in RFC5929 section 3. The unique id
  3. can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".

ssl_bc_server_random : binary

  1. Returns the server random of the back connection when the incoming connection
  2. was made over an SSL/TLS transport layer. It is useful to to decrypt traffic
  3. sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or BoringSSL.

ssl_bc_session_id : binary

  1. Returns the SSL ID of the back connection when the outgoing connection was
  2. made over an SSL/TLS transport layer. It is useful to log if we want to know
  3. if session was reused or not.

ssl_bc_session_key : binary

  1. Returns the SSL session master key of the back connection when the outgoing
  2. connection was made over an SSL/TLS transport layer. It is useful to decrypt
  3. traffic sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or
  4. BoringSSL.

ssl_bc_use_keysize : integer

  1. Returns the symmetric cipher key size used in bits when the outgoing
  2. connection was made over an SSL/TLS transport layer.

ssl_c_ca_err : integer

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the ID of the first error detected during verification of the client
  3. certificate at depth > 0, or 0 if no error was encountered during this
  4. verification process. Please refer to your SSL library's documentation to
  5. find the exhaustive list of error codes.

ssl_c_ca_err_depth : integer

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the depth in the CA chain of the first error detected during the
  3. verification of the client certificate. If no error is encountered, 0 is
  4. returned.

ssl_c_der : binary

  1. Returns the DER formatted certificate presented by the client when the
  2. incoming connection was made over an SSL/TLS transport layer. When used for
  3. an ACL, the value(s) to match against can be passed in hexadecimal form.

ssl_c_err : integer

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the ID of the first error detected during verification at depth 0, or
  3. 0 if no error was encountered during this verification process. Please refer
  4. to your SSL library's documentation to find the exhaustive list of error
  5. codes.

ssl_c_i_dn([[,]]) : string

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the full distinguished name of the issuer of the certificate
  3. presented by the client when no <entry> is specified, or the value of the
  4. first given entry found from the beginning of the DN. If a positive/negative
  5. occurrence number is specified as the optional second argument, it returns
  6. the value of the nth given entry value from the beginning/end of the DN.
  7. For instance, "ssl_c_i_dn(OU,2)" the second organization unit, and
  8. "ssl_c_i_dn(CN)" retrieves the common name.

ssl_c_key_alg : string

  1. Returns the name of the algorithm used to generate the key of the certificate
  2. presented by the client when the incoming connection was made over an SSL/TLS
  3. transport layer.

ssl_c_notafter : string

  1. Returns the end date presented by the client as a formatted string
  2. YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
  3. transport layer.

ssl_c_notbefore : string

  1. Returns the start date presented by the client as a formatted string
  2. YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
  3. transport layer.

ssl_c_s_dn([[,]]) : string

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the full distinguished name of the subject of the certificate
  3. presented by the client when no <entry> is specified, or the value of the
  4. first given entry found from the beginning of the DN. If a positive/negative
  5. occurrence number is specified as the optional second argument, it returns
  6. the value of the nth given entry value from the beginning/end of the DN.
  7. For instance, "ssl_c_s_dn(OU,2)" the second organization unit, and
  8. "ssl_c_s_dn(CN)" retrieves the common name.

ssl_c_serial : binary

  1. Returns the serial of the certificate presented by the client when the
  2. incoming connection was made over an SSL/TLS transport layer. When used for
  3. an ACL, the value(s) to match against can be passed in hexadecimal form.

ssl_c_sha1 : binary

  1. Returns the SHA-1 fingerprint of the certificate presented by the client when
  2. the incoming connection was made over an SSL/TLS transport layer. This can be
  3. used to stick a client to a server, or to pass this information to a server.
  4. Note that the output is binary, so if you want to pass that signature to the
  5. server, you need to encode it in hex or base64, such as in the example below:

Example:

  1. http-request set-header X-SSL-Client-SHA1 %[ssl_c_sha1,hex]

ssl_c_sig_alg : string

  1. Returns the name of the algorithm used to sign the certificate presented by
  2. the client when the incoming connection was made over an SSL/TLS transport
  3. layer.

ssl_c_used : boolean

  1. Returns true if current SSL session uses a client certificate even if current
  2. connection uses SSL session resumption. See also "ssl_fc_has_crt".

ssl_c_verify : integer

  1. Returns the verify result error ID when the incoming connection was made over
  2. an SSL/TLS transport layer, otherwise zero if no error is encountered. Please
  3. refer to your SSL library's documentation for an exhaustive list of error
  4. codes.

ssl_c_version : integer

  1. Returns the version of the certificate presented by the client when the
  2. incoming connection was made over an SSL/TLS transport layer.

ssl_f_der : binary

  1. Returns the DER formatted certificate presented by the frontend when the
  2. incoming connection was made over an SSL/TLS transport layer. When used for
  3. an ACL, the value(s) to match against can be passed in hexadecimal form.

ssl_f_i_dn([[,]]) : string

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the full distinguished name of the issuer of the certificate
  3. presented by the frontend when no <entry> is specified, or the value of the
  4. first given entry found from the beginning of the DN. If a positive/negative
  5. occurrence number is specified as the optional second argument, it returns
  6. the value of the nth given entry value from the beginning/end of the DN.
  7. For instance, "ssl_f_i_dn(OU,2)" the second organization unit, and
  8. "ssl_f_i_dn(CN)" retrieves the common name.

ssl_f_key_alg : string

  1. Returns the name of the algorithm used to generate the key of the certificate
  2. presented by the frontend when the incoming connection was made over an
  3. SSL/TLS transport layer.

ssl_f_notafter : string

  1. Returns the end date presented by the frontend as a formatted string
  2. YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
  3. transport layer.

ssl_f_notbefore : string

  1. Returns the start date presented by the frontend as a formatted string
  2. YYMMDDhhmmss[Z] when the incoming connection was made over an SSL/TLS
  3. transport layer.

ssl_f_s_dn([[,]]) : string

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the full distinguished name of the subject of the certificate
  3. presented by the frontend when no <entry> is specified, or the value of the
  4. first given entry found from the beginning of the DN. If a positive/negative
  5. occurrence number is specified as the optional second argument, it returns
  6. the value of the nth given entry value from the beginning/end of the DN.
  7. For instance, "ssl_f_s_dn(OU,2)" the second organization unit, and
  8. "ssl_f_s_dn(CN)" retrieves the common name.

ssl_f_serial : binary

  1. Returns the serial of the certificate presented by the frontend when the
  2. incoming connection was made over an SSL/TLS transport layer. When used for
  3. an ACL, the value(s) to match against can be passed in hexadecimal form.

ssl_f_sha1 : binary

  1. Returns the SHA-1 fingerprint of the certificate presented by the frontend
  2. when the incoming connection was made over an SSL/TLS transport layer. This
  3. can be used to know which certificate was chosen using SNI.

ssl_f_sig_alg : string

  1. Returns the name of the algorithm used to sign the certificate presented by
  2. the frontend when the incoming connection was made over an SSL/TLS transport
  3. layer.

ssl_f_version : integer

  1. Returns the version of the certificate presented by the frontend when the
  2. incoming connection was made over an SSL/TLS transport layer.

ssl_fc : boolean

  1. Returns true when the front connection was made via an SSL/TLS transport
  2. layer and is locally deciphered. This means it has matched a socket declared
  3. with a "bind" line having the "ssl" option.

Example :

  1. # This passes "X-Proto: https" to servers when client connects over SSL
  2. listen http-https
  3. bind :80
  4. bind :443 ssl crt /etc/haproxy.pem
  5. http-request add-header X-Proto https if { ssl_fc }

ssl_fc_alg_keysize : integer

  1. Returns the symmetric cipher key size supported in bits when the incoming
  2. connection was made over an SSL/TLS transport layer.

ssl_fc_alpn : string

  1. This extracts the Application Layer Protocol Negotiation field from an
  2. incoming connection made via a TLS transport layer and locally deciphered by
  3. haproxy. The result is a string containing the protocol name advertised by
  4. the client. The SSL library must have been built with support for TLS
  5. extensions enabled (check haproxy -vv). Note that the TLS ALPN extension is
  6. not advertised unless the "alpn" keyword on the "bind" line specifies a
  7. protocol list. Also, nothing forces the client to pick a protocol from this
  8. list, any other one may be requested. The TLS ALPN extension is meant to
  9. replace the TLS NPN extension. See also "ssl_fc_npn".

ssl_fc_cipher : string

  1. Returns the name of the used cipher when the incoming connection was made
  2. over an SSL/TLS transport layer.

ssl_fc_cipherlist_bin : binary

  1. Returns the binary form of the client hello cipher list. The maximum returned
  2. value length is according with the value of
  3. "tune.ssl.capture-cipherlist-size".

ssl_fc_cipherlist_hex : string

  1. Returns the binary form of the client hello cipher list encoded as
  2. hexadecimal. The maximum returned value length is according with the value of
  3. "tune.ssl.capture-cipherlist-size".

ssl_fc_cipherlist_str : string

  1. Returns the decoded text form of the client hello cipher list. The maximum
  2. number of ciphers returned is according with the value of
  3. "tune.ssl.capture-cipherlist-size". Note that this sample-fetch is only
  4. available with OpenSSL >= 1.0.2. If the function is not enabled, this
  5. sample-fetch returns the hash like "ssl_fc_cipherlist_xxh".

ssl_fc_cipherlist_xxh : integer

  1. Returns a xxh64 of the cipher list. This hash can be return only is the value
  2. "tune.ssl.capture-cipherlist-size" is set greater than 0, however the hash
  3. take in account all the data of the cipher list.

ssl_fc_client_random : binary

  1. Returns the client random of the front connection when the incoming connection
  2. was made over an SSL/TLS transport layer. It is useful to to decrypt traffic
  3. sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or BoringSSL.

ssl_fc_has_crt : boolean

  1. Returns true if a client certificate is present in an incoming connection over
  2. SSL/TLS transport layer. Useful if 'verify' statement is set to 'optional'.
  3. Note: on SSL session resumption with Session ID or TLS ticket, client
  4. certificate is not present in the current connection but may be retrieved
  5. from the cache or the ticket. So prefer "ssl_c_used" if you want to check if
  6. current SSL session uses a client certificate.

ssl_fc_has_early : boolean

  1. Returns true if early data were sent, and the handshake didn't happen yet. As
  2. it has security implications, it is useful to be able to refuse those, or
  3. wait until the handshake happened.

ssl_fc_has_sni : boolean

  1. This checks for the presence of a Server Name Indication TLS extension (SNI)
  2. in an incoming connection was made over an SSL/TLS transport layer. Returns
  3. true when the incoming connection presents a TLS SNI field. This requires
  4. that the SSL library is built with support for TLS extensions enabled (check
  5. haproxy -vv).

ssl_fc_is_resumed : boolean

  1. Returns true if the SSL/TLS session has been resumed through the use of
  2. SSL session cache or TLS tickets on an incoming connection over an SSL/TLS
  3. transport layer.

ssl_fc_npn : string

  1. This extracts the Next Protocol Negotiation field from an incoming connection
  2. made via a TLS transport layer and locally deciphered by haproxy. The result
  3. is a string containing the protocol name advertised by the client. The SSL
  4. library must have been built with support for TLS extensions enabled (check
  5. haproxy -vv). Note that the TLS NPN extension is not advertised unless the
  6. "npn" keyword on the "bind" line specifies a protocol list. Also, nothing
  7. forces the client to pick a protocol from this list, any other one may be
  8. requested. Please note that the TLS NPN extension was replaced with ALPN.

ssl_fc_protocol : string

  1. Returns the name of the used protocol when the incoming connection was made
  2. over an SSL/TLS transport layer.

ssl_fc_unique_id : binary

  1. When the incoming connection was made over an SSL/TLS transport layer,
  2. returns the TLS unique ID as defined in RFC5929 section 3. The unique id
  3. can be encoded to base64 using the converter: "ssl_bc_unique_id,base64".

ssl_fc_server_random : binary

  1. Returns the server random of the front connection when the incoming connection
  2. was made over an SSL/TLS transport layer. It is useful to to decrypt traffic
  3. sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or BoringSSL.

ssl_fc_session_id : binary

  1. Returns the SSL ID of the front connection when the incoming connection was
  2. made over an SSL/TLS transport layer. It is useful to stick a given client to
  3. a server. It is important to note that some browsers refresh their session ID
  4. every few minutes.

ssl_fc_session_key : binary

  1. Returns the SSL session master key of the front connection when the incoming
  2. connection was made over an SSL/TLS transport layer. It is useful to decrypt
  3. traffic sent using ephemeral ciphers. This requires OpenSSL >= 1.1.0, or
  4. BoringSSL.

ssl_fc_sni : string

  1. This extracts the Server Name Indication TLS extension (SNI) field from an
  2. incoming connection made via an SSL/TLS transport layer and locally
  3. deciphered by haproxy. The result (when present) typically is a string
  4. matching the HTTPS host name (253 chars or less). The SSL library must have
  5. been built with support for TLS extensions enabled (check haproxy -vv).
  6.  
  7. This fetch is different from "req_ssl_sni" above in that it applies to the
  8. connection being deciphered by haproxy and not to SSL contents being blindly
  9. forwarded. See also "ssl_fc_sni_end" and "ssl_fc_sni_reg" below. This
  10. requires that the SSL library is built with support for TLS extensions
  11. enabled (check haproxy -vv).
  12.  
  13. ACL derivatives :
  14. ssl_fc_sni_end : suffix match
  15. ssl_fc_sni_reg : regex match

ssl_fc_use_keysize : integer

  1. Returns the symmetric cipher key size used in bits when the incoming
  2. connection was made over an SSL/TLS transport layer.

7.3.5. Fetching samples from buffer contents (Layer 6)

  1. Fetching samples from buffer contents is a bit different from the previous
  2. sample fetches above because the sampled data are ephemeral. These data can
  3. only be used when they're available and will be lost when they're forwarded.
  4. For this reason, samples fetched from buffer contents during a request cannot
  5. be used in a response for example. Even while the data are being fetched, they
  6. can change. Sometimes it is necessary to set some delays or combine multiple
  7. sample fetch methods to ensure that the expected data are complete and usable,
  8. for example through TCP request content inspection. Please see the "tcp-request
  9. content" keyword for more detailed information on the subject.

payload(,) : binary (deprecated)

  1. This is an alias for "req.payload" when used in the context of a request (e.g.
  2. "stick on", "stick match"), and for "res.payload" when used in the context of
  3. a response such as in "stick store response".

payload_lv(,[,]) : binary (deprecated)

  1. This is an alias for "req.payload_lv" when used in the context of a request
  2. (e.g. "stick on", "stick match"), and for "res.payload_lv" when used in the
  3. context of a response such as in "stick store response".

req.hdrs : string

  1. Returns the current request headers as string including the last empty line
  2. separating headers from the request body. The last empty line can be used to
  3. detect a truncated header block. This sample fetch is useful for some SPOE
  4. headers analyzers and for advanced logging.

req.hdrs_bin : binary

  1. Returns the current request headers contained in preparsed binary form. This
  2. is useful for offloading some processing with SPOE. Each string is described
  3. by a length followed by the number of bytes indicated in the length. The
  4. length is represented using the variable integer encoding detailed in the
  5. SPOE documentation. The end of the list is marked by a couple of empty header
  6. names and values (length of 0 for both).
  7.  
  8. *(<str:header-name><str:header-value>)<empty string><empty string>
  9.  
  10. int: refer to the SPOE documentation for the encoding
  11. str: <int:length><bytes>

req.len : integer

req_len : integer (deprecated)

  1. Returns an integer value corresponding to the number of bytes present in the
  2. request buffer. This is mostly used in ACL. It is important to understand
  3. that this test does not return false as long as the buffer is changing. This
  4. means that a check with equality to zero will almost always immediately match
  5. at the beginning of the session, while a test for more data will wait for
  6. that data to come in and return false only when haproxy is certain that no
  7. more data will come in. This test was designed to be used with TCP request
  8. content inspection.

req.payload(,) : binary

  1. This extracts a binary block of <length> bytes and starting at byte <offset>
  2. in the request buffer. As a special case, if the <length> argument is zero,
  3. the the whole buffer from <offset> to the end is extracted. This can be used
  4. with ACLs in order to check for the presence of some content in a buffer at
  5. any location.
  6.  
  7. ACL alternatives :
  8. payload(<offset>,<length>) : hex binary match

req.payload_lv(,[,]) : binary

  1. This extracts a binary block whose size is specified at <offset1> for <length>
  2. bytes, and which starts at <offset2> if specified or just after the length in
  3. the request buffer. The <offset2> parameter also supports relative offsets if
  4. prepended with a '+' or '-' sign.
  5.  
  6. ACL alternatives :
  7. payload_lv(<offset1>,<length>[,<offset2>]) : hex binary match

Example :

  1. please consult the example from the "stick store-response" keyword.

req.proto_http : boolean

req_proto_http : boolean (deprecated)

  1. Returns true when data in the request buffer look like HTTP and correctly
  2. parses as such. It is the same parser as the common HTTP request parser which
  3. is used so there should be no surprises. The test does not match until the
  4. request is complete, failed or timed out. This test may be used to report the
  5. protocol in TCP logs, but the biggest use is to block TCP request analysis
  6. until a complete HTTP request is present in the buffer, for example to track
  7. a header.

Example:

  1. # track request counts per "base" (concatenation of Host+URL)
  2. tcp-request inspect-delay 10s
  3. tcp-request content reject if !HTTP
  4. tcp-request content track-sc0 base table req-rate

req.rdp_cookie([]) : string

rdp_cookie([]) : string (deprecated)

  1. When the request buffer looks like the RDP protocol, extracts the RDP cookie
  2. <name>, or any cookie if unspecified. The parser only checks for the first
  3. cookie, as illustrated in the RDP protocol specification. The cookie name is
  4. case insensitive. Generally the "MSTS" cookie name will be used, as it can
  5. contain the user name of the client connecting to the server if properly
  6. configured on the client. The "MSTSHASH" cookie is often used as well for
  7. session stickiness to servers.
  8.  
  9. This differs from "balance rdp-cookie" in that any balancing algorithm may be
  10. used and thus the distribution of clients to backend servers is not linked to
  11. a hash of the RDP cookie. It is envisaged that using a balancing algorithm
  12. such as "balance roundrobin" or "balance leastconn" will lead to a more even
  13. distribution of clients to backend servers than the hash used by "balance
  14. rdp-cookie".
  15.  
  16. ACL derivatives :
  17. req_rdp_cookie([<name>]) : exact string match

Example :

  1. listen tse-farm
  2. bind 0.0.0.0:3389
  3. # wait up to 5s for an RDP cookie in the request
  4. tcp-request inspect-delay 5s
  5. tcp-request content accept if RDP_COOKIE
  6. # apply RDP cookie persistence
  7. persist rdp-cookie
  8. # Persist based on the mstshash cookie
  9. # This is only useful makes sense if
  10. # balance rdp-cookie is not used
  11. stick-table type string size 204800
  12. stick on req.rdp_cookie(mstshash)
  13. server srv1 1.1.1.1:3389
  14. server srv1 1.1.1.2:3389

See also : “balance rdp-cookie”, “persist rdp-cookie“, “tcp-request“ and the “req_rdp_cookie” ACL.

req.rdp_cookie_cnt([name]) : integer

rdp_cookie_cnt([name]) : integer (deprecated)

  1. Tries to parse the request buffer as RDP protocol, then returns an integer
  2. corresponding to the number of RDP cookies found. If an optional cookie name
  3. is passed, only cookies matching this name are considered. This is mostly
  4. used in ACL.
  5.  
  6. ACL derivatives :
  7. req_rdp_cookie_cnt([<name>]) : integer match

req.ssl_alpn : string

  1. Returns a string containing the values of the Application-Layer Protocol
  2. Negotiation (ALPN) TLS extension (RFC7301), sent by the client within the SSL
  3. ClientHello message. Note that this only applies to raw contents found in the
  4. request buffer and not to the contents deciphered via an SSL data layer, so
  5. this will not work with "bind" lines having the "ssl" option. This is useful
  6. in ACL to make a routing decision based upon the ALPN preferences of a TLS
  7. client, like in the example below. See also "ssl_fc_alpn".

Examples :

  1. # Wait for a client hello for at most 5 seconds
  2. tcp-request inspect-delay 5s
  3. tcp-request content accept if { req_ssl_hello_type 1 }
  4. use_backend bk_acme if { req.ssl_alpn acme-tls/1 }
  5. default_backend bk_default

req.ssl_ec_ext : boolean

  1. Returns a boolean identifying if client sent the Supported Elliptic Curves
  2. Extension as defined in RFC4492, section 5.1. within the SSL ClientHello
  3. message. This can be used to present ECC compatible clients with EC
  4. certificate and to use RSA for all others, on the same IP address. Note that
  5. this only applies to raw contents found in the request buffer and not to
  6. contents deciphered via an SSL data layer, so this will not work with "bind"
  7. lines having the "ssl" option.

req.ssl_hello_type : integer

req_ssl_hello_type : integer (deprecated)

  1. Returns an integer value containing the type of the SSL hello message found
  2. in the request buffer if the buffer contains data that parse as a complete
  3. SSL (v3 or superior) client hello message. Note that this only applies to raw
  4. contents found in the request buffer and not to contents deciphered via an
  5. SSL data layer, so this will not work with "bind" lines having the "ssl"
  6. option. This is mostly used in ACL to detect presence of an SSL hello message
  7. that is supposed to contain an SSL session ID usable for stickiness.

req.ssl_sni : string

req_ssl_sni : string (deprecated)

  1. Returns a string containing the value of the Server Name TLS extension sent
  2. by a client in a TLS stream passing through the request buffer if the buffer
  3. contains data that parse as a complete SSL (v3 or superior) client hello
  4. message. Note that this only applies to raw contents found in the request
  5. buffer and not to contents deciphered via an SSL data layer, so this will not
  6. work with "bind" lines having the "ssl" option. SNI normally contains the
  7. name of the host the client tries to connect to (for recent browsers). SNI is
  8. useful for allowing or denying access to certain hosts when SSL/TLS is used
  9. by the client. This test was designed to be used with TCP request content
  10. inspection. If content switching is needed, it is recommended to first wait
  11. for a complete client hello (type 1), like in the example below. See also
  12. "ssl_fc_sni".
  13.  
  14. ACL derivatives :
  15. req_ssl_sni : exact string match

Examples :

  1. # Wait for a client hello for at most 5 seconds
  2. tcp-request inspect-delay 5s
  3. tcp-request content accept if { req_ssl_hello_type 1 }
  4. use_backend bk_allow if { req_ssl_sni -f allowed_sites }
  5. default_backend bk_sorry_page

req.ssl_st_ext : integer

  1. Returns 0 if the client didn't send a SessionTicket TLS Extension (RFC5077)
  2. Returns 1 if the client sent SessionTicket TLS Extension
  3. Returns 2 if the client also sent non-zero length TLS SessionTicket
  4. Note that this only applies to raw contents found in the request buffer and
  5. not to contents deciphered via an SSL data layer, so this will not work with
  6. "bind" lines having the "ssl" option. This can for example be used to detect
  7. whether the client sent a SessionTicket or not and stick it accordingly, if
  8. no SessionTicket then stick on SessionID or don't stick as there's no server
  9. side state is there when SessionTickets are in use.

req.ssl_ver : integer

req_ssl_ver : integer (deprecated)

  1. Returns an integer value containing the version of the SSL/TLS protocol of a
  2. stream present in the request buffer. Both SSLv2 hello messages and SSLv3
  3. messages are supported. TLSv1 is announced as SSL version 3.1. The value is
  4. composed of the major version multiplied by 65536, added to the minor
  5. version. Note that this only applies to raw contents found in the request
  6. buffer and not to contents deciphered via an SSL data layer, so this will not
  7. work with "bind" lines having the "ssl" option. The ACL version of the test
  8. matches against a decimal notation in the form MAJOR.MINOR (e.g. 3.1). This
  9. fetch is mostly used in ACL.
  10.  
  11. ACL derivatives :
  12. req_ssl_ver : decimal match

res.len : integer

  1. Returns an integer value corresponding to the number of bytes present in the
  2. response buffer. This is mostly used in ACL. It is important to understand
  3. that this test does not return false as long as the buffer is changing. This
  4. means that a check with equality to zero will almost always immediately match
  5. at the beginning of the session, while a test for more data will wait for
  6. that data to come in and return false only when haproxy is certain that no
  7. more data will come in. This test was designed to be used with TCP response
  8. content inspection.

res.payload(,) : binary

  1. This extracts a binary block of <length> bytes and starting at byte <offset>
  2. in the response buffer. As a special case, if the <length> argument is zero,
  3. the the whole buffer from <offset> to the end is extracted. This can be used
  4. with ACLs in order to check for the presence of some content in a buffer at
  5. any location.

res.payload_lv(,[,]) : binary

  1. This extracts a binary block whose size is specified at <offset1> for <length>
  2. bytes, and which starts at <offset2> if specified or just after the length in
  3. the response buffer. The <offset2> parameter also supports relative offsets
  4. if prepended with a '+' or '-' sign.

Example :

  1. please consult the example from the "stick store-response" keyword.

res.ssl_hello_type : integer

rep_ssl_hello_type : integer (deprecated)

  1. Returns an integer value containing the type of the SSL hello message found
  2. in the response buffer if the buffer contains data that parses as a complete
  3. SSL (v3 or superior) hello message. Note that this only applies to raw
  4. contents found in the response buffer and not to contents deciphered via an
  5. SSL data layer, so this will not work with "server" lines having the "ssl"
  6. option. This is mostly used in ACL to detect presence of an SSL hello message
  7. that is supposed to contain an SSL session ID usable for stickiness.

wait_end : boolean

  1. This fetch either returns true when the inspection period is over, or does
  2. not fetch. It is only used in ACLs, in conjunction with content analysis to
  3. avoid returning a wrong verdict early. It may also be used to delay some
  4. actions, such as a delayed reject for some special addresses. Since it either
  5. stops the rules evaluation or immediately returns true, it is recommended to
  6. use this acl as the last one in a rule. Please note that the default ACL
  7. "WAIT_END" is always usable without prior declaration. This test was designed
  8. to be used with TCP request content inspection.

Examples :

  1. # delay every incoming request by 2 seconds
  2. tcp-request inspect-delay 2s
  3. tcp-request content accept if WAIT_END
  4. # don't immediately tell bad guys they are rejected
  5. tcp-request inspect-delay 10s
  6. acl goodguys src 10.0.0.0/24
  7. acl badguys src 10.0.1.0/24
  8. tcp-request content accept if goodguys
  9. tcp-request content reject if badguys WAIT_END
  10. tcp-request content reject

7.3.6. Fetching HTTP samples (Layer 7)

  1. It is possible to fetch samples from HTTP contents, requests and responses.
  2. This application layer is also called layer 7. It is only possible to fetch the
  3. data in this section when a full HTTP request or response has been parsed from
  4. its respective request or response buffer. This is always the case with all
  5. HTTP specific rules and for sections running with "mode http". When using TCP
  6. content inspection, it may be necessary to support an inspection delay in order
  7. to let the request or response come in first. These fetches may require a bit
  8. more CPU resources than the layer 4 ones, but not much since the request and
  9. response are indexed.

base : string

  1. This returns the concatenation of the first Host header and the path part of
  2. the request, which starts at the first slash and ends before the question
  3. mark. It can be useful in virtual hosted environments to detect URL abuses as
  4. well as to improve shared caches efficiency. Using this with a limited size
  5. stick table also allows one to collect statistics about most commonly
  6. requested objects by host/path. With ACLs it can allow simple content
  7. switching rules involving the host and the path at the same time, such as
  8. "www.example.com/favicon.ico". See also "path" and "uri".
  9.  
  10. ACL derivatives :
  11. base : exact string match
  12. base_beg : prefix match
  13. base_dir : subdir match
  14. base_dom : domain match
  15. base_end : suffix match
  16. base_len : length match
  17. base_reg : regex match
  18. base_sub : substring match

base32 : integer

  1. This returns a 32-bit hash of the value returned by the "base" fetch method
  2. above. This is useful to track per-URL activity on high traffic sites without
  3. having to store all URLs. Instead a shorter hash is stored, saving a lot of
  4. memory. The output type is an unsigned integer. The hash function used is
  5. SDBM with full avalanche on the output. Technically, base32 is exactly equal
  6. to "base,sdbm(1)".

base32+src : binary

  1. This returns the concatenation of the base32 fetch above and the src fetch
  2. below. The resulting type is of type binary, with a size of 8 or 20 bytes
  3. depending on the source address family. This can be used to track per-IP,
  4. per-URL counters.

capture.req.hdr() : string

  1. This extracts the content of the header captured by the "capture request
  2. header", idx is the position of the capture keyword in the configuration.

See also:capture request header“.

capture.req.method : string

  1. This extracts the METHOD of an HTTP request. It can be used in both request
  2. and response. Unlike "method", it can be used in both request and response
  3. because it's allocated.

capture.req.uri : string

  1. This extracts the request's URI, which starts at the first slash and ends
  2. before the first space in the request (without the host part). Unlike "path"
  3. and "url", it can be used in both request and response because it's
  4. allocated.

capture.req.ver : string

  1. This extracts the request's HTTP version and returns either "HTTP/1.0" or
  2. "HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and
  3. logs because it relies on a persistent flag.

capture.res.hdr() : string

  1. This extracts the content of the header captured by the "capture response
  2. header", idx is the position of the capture keyword in the configuration.
  3. The first entry is an index of 0.

See also:capture response header

capture.res.ver : string

  1. This extracts the response's HTTP version and returns either "HTTP/1.0" or
  2. "HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a
  3. persistent flag.

req.body : binary

  1. This returns the HTTP request's available body as a block of data. It
  2. requires that the request body has been buffered made available using
  3. "option http-buffer-request". In case of chunked-encoded body, currently only
  4. the first chunk is analyzed.

req.body_param([) : string

  1. This fetch assumes that the body of the POST request is url-encoded. The user
  2. can check if the "content-type" contains the value
  3. "application/x-www-form-urlencoded". This extracts the first occurrence of the
  4. parameter <name> in the body, which ends before '&'. The parameter name is
  5. case-sensitive. If no name is given, any parameter will match, and the first
  6. one will be returned. The result is a string corresponding to the value of the
  7. parameter <name> as presented in the request body (no URL decoding is
  8. performed). Note that the ACL version of this fetch iterates over multiple
  9. parameters and will iteratively report all parameters values if no name is
  10. given.

req.body_len : integer

  1. This returns the length of the HTTP request's available body in bytes. It may
  2. be lower than the advertised length if the body is larger than the buffer. It
  3. requires that the request body has been buffered made available using
  4. "option http-buffer-request".

req.body_size : integer

  1. This returns the advertised length of the HTTP request's body in bytes. It
  2. will represent the advertised Content-Length header, or the size of the first
  3. chunk in case of chunked encoding. In order to parse the chunks, it requires
  4. that the request body has been buffered made available using
  5. "option http-buffer-request".

req.cook([]) : string

cook([]) : string (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Cookie"
  2. header line from the request, and returns its value as string. If no name is
  3. specified, the first cookie value is returned. When used with ACLs, all
  4. matching cookies are evaluated. Spaces around the name and the value are
  5. ignored as requested by the Cookie header specification (RFC6265). The cookie
  6. name is case-sensitive. Empty cookies are valid, so an empty cookie may very
  7. well return an empty value if it is present. Use the "found" match to detect
  8. presence. Use the res.cook() variant for response cookies sent by the server.
  9.  
  10. ACL derivatives :
  11. cook([<name>]) : exact string match
  12. cook_beg([<name>]) : prefix match
  13. cook_dir([<name>]) : subdir match
  14. cook_dom([<name>]) : domain match
  15. cook_end([<name>]) : suffix match
  16. cook_len([<name>]) : length match
  17. cook_reg([<name>]) : regex match
  18. cook_sub([<name>]) : substring match

req.cook_cnt([]) : integer

cook_cnt([]) : integer (deprecated)

  1. Returns an integer value representing the number of occurrences of the cookie
  2. <name> in the request, or all cookies if <name> is not specified.

req.cook_val([]) : integer

cook_val([]) : integer (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Cookie"
  2. header line from the request, and converts its value to an integer which is
  3. returned. If no name is specified, the first cookie value is returned. When
  4. used in ACLs, all matching names are iterated over until a value matches.

cookie([]) : string (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Cookie"
  2. header line from the request, or a "Set-Cookie" header from the response, and
  3. returns its value as a string. A typical use is to get multiple clients
  4. sharing a same profile use the same server. This can be similar to what
  5. "appsession" did with the "request-learn" statement, but with support for
  6. multi-peer synchronization and state keeping across restarts. If no name is
  7. specified, the first cookie value is returned. This fetch should not be used
  8. anymore and should be replaced by req.cook() or res.cook() instead as it
  9. ambiguously uses the direction based on the context where it is used.

hdr([[,]]) : string

  1. This is equivalent to req.hdr() when used on requests, and to res.hdr() when
  2. used on responses. Please refer to these respective fetches for more details.
  3. In case of doubt about the fetch direction, please use the explicit ones.
  4. Note that contrary to the hdr() sample fetch method, the hdr_* ACL keywords
  5. unambiguously apply to the request headers.

req.fhdr([,]) : string

  1. This extracts the last occurrence of header <name> in an HTTP request. When
  2. used from an ACL, all occurrences are iterated over until a match is found.
  3. Optionally, a specific occurrence might be specified as a position number.
  4. Positive values indicate a position from the first occurrence, with 1 being
  5. the first one. Negative values indicate positions relative to the last one,
  6. with -1 being the last one. It differs from req.hdr() in that any commas
  7. present in the value are returned and are not used as delimiters. This is
  8. sometimes useful with headers such as User-Agent.

req.fhdr_cnt([]) : integer

  1. Returns an integer value representing the number of occurrences of request
  2. header field name <name>, or the total number of header fields if <name> is
  3. not specified. Contrary to its req.hdr_cnt() cousin, this function returns
  4. the number of full line headers and does not stop on commas.

req.hdr([[,]]) : string

  1. This extracts the last occurrence of header <name> in an HTTP request. When
  2. used from an ACL, all occurrences are iterated over until a match is found.
  3. Optionally, a specific occurrence might be specified as a position number.
  4. Positive values indicate a position from the first occurrence, with 1 being
  5. the first one. Negative values indicate positions relative to the last one,
  6. with -1 being the last one. A typical use is with the X-Forwarded-For header
  7. once converted to IP, associated with an IP stick-table. The function
  8. considers any comma as a delimiter for distinct values. If full-line headers
  9. are desired instead, use req.fhdr(). Please carefully check RFC7231 to know
  10. how certain headers are supposed to be parsed. Also, some of them are case
  11. insensitive (e.g. Connection).
  12.  
  13. ACL derivatives :
  14. hdr([<name>[,<occ>]]) : exact string match
  15. hdr_beg([<name>[,<occ>]]) : prefix match
  16. hdr_dir([<name>[,<occ>]]) : subdir match
  17. hdr_dom([<name>[,<occ>]]) : domain match
  18. hdr_end([<name>[,<occ>]]) : suffix match
  19. hdr_len([<name>[,<occ>]]) : length match
  20. hdr_reg([<name>[,<occ>]]) : regex match
  21. hdr_sub([<name>[,<occ>]]) : substring match

req.hdr_cnt([]) : integer

hdr_cnt([

]) : integer (deprecated)

  1. Returns an integer value representing the number of occurrences of request
  2. header field name <name>, or the total number of header field values if
  3. <name> is not specified. It is important to remember that one header line may
  4. count as several headers if it has several values. The function considers any
  5. comma as a delimiter for distinct values. If full-line headers are desired
  6. instead, req.fhdr_cnt() should be used instead. With ACLs, it can be used to
  7. detect presence, absence or abuse of a specific header, as well as to block
  8. request smuggling attacks by rejecting requests which contain more than one
  9. of certain headers. See "req.hdr" for more information on header matching.

req.hdr_ip([[,]]) : ip

hdr_ip([[,]]) : ip (deprecated)

  1. This extracts the last occurrence of header <name> in an HTTP request,
  2. converts it to an IPv4 or IPv6 address and returns this address. When used
  3. with ACLs, all occurrences are checked, and if <name> is omitted, every value
  4. of every header is checked. Optionally, a specific occurrence might be
  5. specified as a position number. Positive values indicate a position from the
  6. first occurrence, with 1 being the first one. Negative values indicate
  7. positions relative to the last one, with -1 being the last one. A typical use
  8. is with the X-Forwarded-For and X-Client-IP headers.

req.hdr_val([[,]]) : integer

hdr_val([[,]]) : integer (deprecated)

  1. This extracts the last occurrence of header <name> in an HTTP request, and
  2. converts it to an integer value. When used with ACLs, all occurrences are
  3. checked, and if <name> is omitted, every value of every header is checked.
  4. Optionally, a specific occurrence might be specified as a position number.
  5. Positive values indicate a position from the first occurrence, with 1 being
  6. the first one. Negative values indicate positions relative to the last one,
  7. with -1 being the last one. A typical use is with the X-Forwarded-For header.

http_auth() : boolean

  1. Returns a boolean indicating whether the authentication data received from
  2. the client match a username & password stored in the specified userlist. This
  3. fetch function is not really useful outside of ACLs. Currently only http
  4. basic auth is supported.

http_auth_group() : string

  1. Returns a string corresponding to the user name found in the authentication
  2. data received from the client if both the user name and password are valid
  3. according to the specified userlist. The main purpose is to use it in ACLs
  4. where it is then checked whether the user belongs to any group within a list.
  5. This fetch function is not really useful outside of ACLs. Currently only http
  6. basic auth is supported.
  7.  
  8. ACL derivatives :
  9. http_auth_group(<userlist>) : group ...
  10. Returns true when the user extracted from the request and whose password is
  11. valid according to the specified userlist belongs to at least one of the
  12. groups.

http_first_req : boolean

  1. Returns true when the request being processed is the first one of the
  2. connection. This can be used to add or remove headers that may be missing
  3. from some requests when a request is not the first one, or to help grouping
  4. requests in the logs.

method : integer + string

  1. Returns an integer value corresponding to the method in the HTTP request. For
  2. example, "GET" equals 1 (check sources to establish the matching). Value 9
  3. means "other method" and may be converted to a string extracted from the
  4. stream. This should not be used directly as a sample, this is only meant to
  5. be used from ACLs, which transparently convert methods from patterns to these
  6. integer + string values. Some predefined ACL already check for most common
  7. methods.
  8.  
  9. ACL derivatives :
  10. method : case insensitive method match

Example :

  1. # only accept GET and HEAD requests
  2. acl valid_method method GET HEAD
  3. http-request deny if ! valid_method

path : string

  1. This extracts the request's URL path, which starts at the first slash and
  2. ends before the question mark (without the host part). A typical use is with
  3. prefetch-capable caches, and with portals which need to aggregate multiple
  4. information from databases and keep them in caches. Note that with outgoing
  5. caches, it would be wiser to use "url" instead. With ACLs, it's typically
  6. used to match exact file names (e.g. "/login.php"), or directory parts using
  7. the derivative forms. See also the "url" and "base" fetch methods.
  8.  
  9. ACL derivatives :
  10. path : exact string match
  11. path_beg : prefix match
  12. path_dir : subdir match
  13. path_dom : domain match
  14. path_end : suffix match
  15. path_len : length match
  16. path_reg : regex match
  17. path_sub : substring match

query : string

  1. This extracts the request's query string, which starts after the first
  2. question mark. If no question mark is present, this fetch returns nothing. If
  3. a question mark is present but nothing follows, it returns an empty string.
  4. This means it's possible to easily know whether a query string is present
  5. using the "found" matching method. This fetch is the complement of "path"
  6. which stops before the question mark.

req.hdr_names([]) : string

  1. This builds a string made from the concatenation of all header names as they
  2. appear in the request when the rule is evaluated. The default delimiter is
  3. the comma (',') but it may be overridden as an optional argument <delim>. In
  4. this case, only the first character of <delim> is considered.

req.ver : string

req_ver : string (deprecated)

  1. Returns the version string from the HTTP request, for example "1.1". This can
  2. be useful for logs, but is mostly there for ACL. Some predefined ACL already
  3. check for versions 1.0 and 1.1.
  4.  
  5. ACL derivatives :
  6. req_ver : exact string match

res.comp : boolean

  1. Returns the boolean "true" value if the response has been compressed by
  2. HAProxy, otherwise returns boolean "false". This may be used to add
  3. information in the logs.

res.comp_algo : string

  1. Returns a string containing the name of the algorithm used if the response
  2. was compressed by HAProxy, for example : "deflate". This may be used to add
  3. some information in the logs.

res.cook([]) : string

scook([]) : string (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
  2. header line from the response, and returns its value as string. If no name is
  3. specified, the first cookie value is returned.
  4.  
  5. ACL derivatives :
  6. scook([<name>] : exact string match

res.cook_cnt([]) : integer

scook_cnt([]) : integer (deprecated)

  1. Returns an integer value representing the number of occurrences of the cookie
  2. <name> in the response, or all cookies if <name> is not specified. This is
  3. mostly useful when combined with ACLs to detect suspicious responses.

res.cook_val([]) : integer

scook_val([]) : integer (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
  2. header line from the response, and converts its value to an integer which is
  3. returned. If no name is specified, the first cookie value is returned.

res.fhdr([[,]]) : string

  1. This extracts the last occurrence of header <name> in an HTTP response, or of
  2. the last header if no <name> is specified. Optionally, a specific occurrence
  3. might be specified as a position number. Positive values indicate a position
  4. from the first occurrence, with 1 being the first one. Negative values
  5. indicate positions relative to the last one, with -1 being the last one. It
  6. differs from res.hdr() in that any commas present in the value are returned
  7. and are not used as delimiters. If this is not desired, the res.hdr() fetch
  8. should be used instead. This is sometimes useful with headers such as Date or
  9. Expires.

res.fhdr_cnt([]) : integer

  1. Returns an integer value representing the number of occurrences of response
  2. header field name <name>, or the total number of header fields if <name> is
  3. not specified. Contrary to its res.hdr_cnt() cousin, this function returns
  4. the number of full line headers and does not stop on commas. If this is not
  5. desired, the res.hdr_cnt() fetch should be used instead.

res.hdr([[,]]) : string

shdr([[,]]) : string (deprecated)

  1. This extracts the last occurrence of header <name> in an HTTP response, or of
  2. the last header if no <name> is specified. Optionally, a specific occurrence
  3. might be specified as a position number. Positive values indicate a position
  4. from the first occurrence, with 1 being the first one. Negative values
  5. indicate positions relative to the last one, with -1 being the last one. This
  6. can be useful to learn some data into a stick-table. The function considers
  7. any comma as a delimiter for distinct values. If this is not desired, the
  8. res.fhdr() fetch should be used instead.
  9.  
  10. ACL derivatives :
  11. shdr([<name>[,<occ>]]) : exact string match
  12. shdr_beg([<name>[,<occ>]]) : prefix match
  13. shdr_dir([<name>[,<occ>]]) : subdir match
  14. shdr_dom([<name>[,<occ>]]) : domain match
  15. shdr_end([<name>[,<occ>]]) : suffix match
  16. shdr_len([<name>[,<occ>]]) : length match
  17. shdr_reg([<name>[,<occ>]]) : regex match
  18. shdr_sub([<name>[,<occ>]]) : substring match

res.hdr_cnt([]) : integer

shdr_cnt([]) : integer (deprecated)

  1. Returns an integer value representing the number of occurrences of response
  2. header field name <name>, or the total number of header fields if <name> is
  3. not specified. The function considers any comma as a delimiter for distinct
  4. values. If this is not desired, the res.fhdr_cnt() fetch should be used
  5. instead.

res.hdr_ip([[,]]) : ip

shdr_ip([[,]]) : ip (deprecated)

  1. This extracts the last occurrence of header <name> in an HTTP response,
  2. convert it to an IPv4 or IPv6 address and returns this address. Optionally, a
  3. specific occurrence might be specified as a position number. Positive values
  4. indicate a position from the first occurrence, with 1 being the first one.
  5. Negative values indicate positions relative to the last one, with -1 being
  6. the last one. This can be useful to learn some data into a stick table.

res.hdr_names([]) : string

  1. This builds a string made from the concatenation of all header names as they
  2. appear in the response when the rule is evaluated. The default delimiter is
  3. the comma (',') but it may be overridden as an optional argument <delim>. In
  4. this case, only the first character of <delim> is considered.

res.hdr_val([[,]]) : integer

shdr_val([[,]]) : integer (deprecated)

  1. This extracts the last occurrence of header <name> in an HTTP response, and
  2. converts it to an integer value. Optionally, a specific occurrence might be
  3. specified as a position number. Positive values indicate a position from the
  4. first occurrence, with 1 being the first one. Negative values indicate
  5. positions relative to the last one, with -1 being the last one. This can be
  6. useful to learn some data into a stick table.

res.ver : string

resp_ver : string (deprecated)

  1. Returns the version string from the HTTP response, for example "1.1". This
  2. can be useful for logs, but is mostly there for ACL.
  3.  
  4. ACL derivatives :
  5. resp_ver : exact string match

set-cookie([]) : string (deprecated)

  1. This extracts the last occurrence of the cookie name <name> on a "Set-Cookie"
  2. header line from the response and uses the corresponding value to match. This
  3. can be comparable to what "appsession" did with default options, but with
  4. support for multi-peer synchronization and state keeping across restarts.
  5.  
  6. This fetch function is deprecated and has been superseded by the "res.cook"
  7. fetch. This keyword will disappear soon.

status : integer

  1. Returns an integer containing the HTTP status code in the HTTP response, for
  2. example, 302. It is mostly used within ACLs and integer ranges, for example,
  3. to remove any Location header if the response is not a 3xx.

unique-id : string

  1. Returns the unique-id attached to the request. The directive
  2. "unique-id-format" must be set. If it is not set, the unique-id sample fetch
  3. fails. Note that the unique-id is usually used with HTTP requests, however this
  4. sample fetch can be used with other protocols. Obviously, if it is used with
  5. other protocols than HTTP, the unique-id-format directive must not contain
  6. HTTP parts. See: unique-id-format and unique-id-header

url : string

  1. This extracts the request's URL as presented in the request. A typical use is
  2. with prefetch-capable caches, and with portals which need to aggregate
  3. multiple information from databases and keep them in caches. With ACLs, using
  4. "path" is preferred over using "url", because clients may send a full URL as
  5. is normally done with proxies. The only real use is to match "*" which does
  6. not match in "path", and for which there is already a predefined ACL. See
  7. also "path" and "base".
  8.  
  9. ACL derivatives :
  10. url : exact string match
  11. url_beg : prefix match
  12. url_dir : subdir match
  13. url_dom : domain match
  14. url_end : suffix match
  15. url_len : length match
  16. url_reg : regex match
  17. url_sub : substring match

url_ip : ip

  1. This extracts the IP address from the request's URL when the host part is
  2. presented as an IP address. Its use is very limited. For instance, a
  3. monitoring system might use this field as an alternative for the source IP in
  4. order to test what path a given source address would follow, or to force an
  5. entry in a table for a given source address. With ACLs it can be used to
  6. restrict access to certain systems through a proxy, for example when combined
  7. with option "http_proxy".

url_port : integer

  1. This extracts the port part from the request's URL. Note that if the port is
  2. not specified in the request, port 80 is assumed. With ACLs it can be used to
  3. restrict access to certain systems through a proxy, for example when combined
  4. with option "http_proxy".

urlp([[,]]) : string

url_param([[,]]) : string

  1. This extracts the first occurrence of the parameter <name> in the query
  2. string, which begins after either '?' or <delim>, and which ends before '&',
  3. ';' or <delim>. The parameter name is case-sensitive. If no name is given,
  4. any parameter will match, and the first one will be returned. The result is
  5. a string corresponding to the value of the parameter <name> as presented in
  6. the request (no URL decoding is performed). This can be used for session
  7. stickiness based on a client ID, to extract an application cookie passed as a
  8. URL parameter, or in ACLs to apply some checks. Note that the ACL version of
  9. this fetch iterates over multiple parameters and will iteratively report all
  10. parameters values if no name is given
  11.  
  12. ACL derivatives :
  13. urlp(<name>[,<delim>]) : exact string match
  14. urlp_beg(<name>[,<delim>]) : prefix match
  15. urlp_dir(<name>[,<delim>]) : subdir match
  16. urlp_dom(<name>[,<delim>]) : domain match
  17. urlp_end(<name>[,<delim>]) : suffix match
  18. urlp_len(<name>[,<delim>]) : length match
  19. urlp_reg(<name>[,<delim>]) : regex match
  20. urlp_sub(<name>[,<delim>]) : substring match

Example :

  1. # match http://example.com/foo?PHPSESSIONID=some_id
  2. stick on urlp(PHPSESSIONID)
  3. # match http://example.com/foo;JSESSIONID=some_id
  4. stick on urlp(JSESSIONID,;)

urlp_val([[,]]) : integer

  1. See "urlp" above. This one extracts the URL parameter <name> in the request
  2. and converts it to an integer value. This can be used for session stickiness
  3. based on a user ID for example, or with ACLs to match a page number or price.

url32 : integer

  1. This returns a 32-bit hash of the value obtained by concatenating the first
  2. Host header and the whole URL including parameters (not only the path part of
  3. the request, as in the "base32" fetch above). This is useful to track per-URL
  4. activity. A shorter hash is stored, saving a lot of memory. The output type
  5. is an unsigned integer.

url32+src : binary

  1. This returns the concatenation of the "url32" fetch and the "src" fetch. The
  2. resulting type is of type binary, with a size of 8 or 20 bytes depending on
  3. the source address family. This can be used to track per-IP, per-URL counters.