Headers
This section describes matcher functions designed to target and match HTTP headers in incoming HTTP requests.
header
Sets the expected HTTP header and its value for the request to match. This function ensures that the specified header with the given value is present in the request. Header names are case-insensitive, as per RFC 2616.
Parameters
name
: The HTTP header name. Header names are case-insensitive.value
: The expected value of the HTTP header.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_not
Sets the requirement that the HTTP request must not contain a specific header with the specified value. This function ensures that the specified header with the given value is absent in the request. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to add multiple excluded headers.
Parameters
name
: The HTTP header name. Header names are case-insensitive.value
: The value of the HTTP header that must not be present.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_exists
Sets the requirement that the HTTP request must contain a specific header. The presence of the header is checked, but its value is not validated. For value validation, refer to Mock::expect_header.
Parameters
name
: The HTTP header name. Header names are case-insensitive, as per RFC 2616.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_missing
Sets the requirement that the HTTP request must not contain a specific header. This function ensures that the specified header is absent in the request. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to add multiple excluded headers.
Parameters
name
: The HTTP header name. Header names are case-insensitive.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_includes
Sets the requirement that the HTTP request must contain a specific header whose value contains a specified substring. This function ensures that the specified header is present and its value contains the given substring. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and substrings.
Parameters
name
: The HTTP header name. Header names are case-insensitive.substring
: The substring that the header value must contain.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_excludes
Sets the requirement that the HTTP request must contain a specific header whose value does not contain a specified substring. This function ensures that the specified header is present and its value does not contain the given substring. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and substrings.
Parameters
name
: The HTTP header name. Header names are case-insensitive.substring
: The substring that the header value must not contain.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_prefix
Sets the requirement that the HTTP request must contain a specific header whose value starts with a specified prefix. This function ensures that the specified header is present and its value starts with the given prefix. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and prefixes.
Parameters
name
: The HTTP header name. Header names are case-insensitive.prefix
: The prefix that the header value must start with.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_prefix_not
Sets the requirement that the HTTP request must contain a specific header whose value does not start with a specified prefix. This function ensures that the specified header is present and its value does not start with the given prefix. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and prefixes.
Parameters
name
: The HTTP header name. Header names are case-insensitive.prefix
: The prefix that the header value must not start with.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_suffix
Sets the requirement that the HTTP request must contain a specific header whose value ends with a specified suffix. This function ensures that the specified header is present and its value ends with the given suffix. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and suffixes.
Parameters
name
: The HTTP header name. Header names are case-insensitive.suffix
: The suffix that the header value must end with.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_suffix_not
Sets the requirement that the HTTP request must contain a specific header whose value does not end with a specified suffix. This function ensures that the specified header is present and its value does not end with the given suffix. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and suffixes.
Parameters
name
: The HTTP header name. Header names are case-insensitive.suffix
: The suffix that the header value must not end with.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_matches
Sets the requirement that the HTTP request must contain a specific header whose key and value match the specified regular expressions. This function ensures that the specified header is present and both its key and value match the given regular expressions. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple headers and patterns.
Parameters
key_regex
: The regular expression that the header key must match.value_regex
: The regular expression that the header value must match.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
header_count
Sets the requirement that the HTTP request must contain a specific number of headers whose keys and values match specified patterns. This function ensures that the specified number of headers with keys and values matching the given patterns are present in the request. Header names are case-insensitive, as per RFC 2616.
This function may be called multiple times to check multiple patterns and counts.
Parameters
key_pattern
: The pattern that the header keys must match.value_pattern
: The pattern that the header values must match.count
: The number of headers with keys and values matching the patterns that must be present.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.