HTTP request header fields
The Rules language includes fields that represent properties of HTTP request headers. Many of these return arrays containing the respective values.
The Cloudflare Rules language supports these HTTP header fields.
http.request.headers
Map<Array<String>>
The HTTP request headers represented as a Map (or associative array).
The keys of the associative array are the names of HTTP request headers converted to lowercase.
When there are repeating headers, the array includes them in the order they appear in the request.
The request header values are not pre-processed and retain the original case used in the request.
- Decoding: no decoding performed
- Whitespace: preserved
- Non-ASCII: preserved
Example:
Example value:
http.request.headers.names
Array<String>
The names of the headers in the HTTP request.
The names are not pre-processed and retain the original case used in the request.
The order of header names is not guaranteed but will match http.request.headers.values
.
Duplicate headers are listed multiple times.
- Decoding: no decoding performed
- Whitespace: preserved
- Non-ASCII: preserved
Example:
Example value: ["content-type"]
http.request.headers.values
Array<String>
The values of the headers in the HTTP request.
The values are not pre-processed and retain the original case used in the request.
The order of header values is not guaranteed but will match http.request.headers.names
.
Duplicate headers are listed multiple times.
- Decoding: no decoding performed
- Whitespace: preserved
- Non-ASCII: preserved
Example 1:
Example value 1:
Additionally used to match requests according to the specified operator and the length/size entered for the header value.
Example 2:
Example value 2:
http.request.headers.truncated
Boolean
Returns true
when the HTTP request contains too many headers; otherwise, returns false
.
When true
, http.request.headers
, http.request.headers.names
, and http.request.headers.values
may not contain all of the headers sent in the HTTP request.
http.request.accepted_languages
Array<String>
List of language tags provided in the Accept-Language
↗ HTTP request header, sorted by weight (;q=<weight>
, with a default weight of 1
) in descending order.
If the HTTP header is not present in the request or is empty, http.request.accepted_languages[0]
will return a “missing value”, which the concat()
function will handle as an empty string.
If the HTTP header includes the language tag *
it will not be stored in the array.
Example 1:
Request with header Accept-Language: fr-CH, fr;q=0.8, en;q=0.9, de;q=0.7, *;q=0.5
. In this case:
http.request.accepted_languages[0] == "fr-CH"
http.request.accepted_languages == ["fr-CH", "en", "fr", "de"]
Example 2:
Request without an Accept-Language
HTTP header and a URI of https://www.example.com/my-path
. In this case:
concat("/", http.request.accepted_languages[0], http.request.uri.path) == "//my-path"
.