Cookie
This section describes matcher functions designed to target and match cookies headers in incoming HTTP requests.
Attention: To use these matchers, enable the cookies feature by adding
--features=cookies
to your Cargo command. For example:cargo test --features=cookies
.
cookie
Sets the cookie that needs to exist in the HTTP request. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie. Must be a case-sensitive match.value
: The expected value of the cookie.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_not
Sets the cookie that should not exist or should not have a specific value in the HTTP request. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie. Must be a case-sensitive match.value
: The value that the cookie should not have.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_exists
Sets the requirement that a cookie with the specified name must exist in the HTTP request. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_missing
Sets the requirement that a cookie with the specified name must not exist in the HTTP request. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must not exist.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_includes
Sets the requirement that a cookie with the specified name must exist and its value must contain the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_substring
: The substring that must be present in the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_excludes
Sets the requirement that a cookie with the specified name must exist and its value must not contain the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_substring
: The substring that must not be present in the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_prefix
Sets the requirement that a cookie with the specified name must exist and its value must start with the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_prefix
: The substring that must be at the start of the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_prefix_not
Sets the requirement that a cookie with the specified name must exist and its value must not start with the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_prefix
: The substring that must not be at the start of the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_suffix
Sets the requirement that a cookie with the specified name must exist and its value must end with the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_suffix
: The substring that must be at the end of the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_suffix_not
Sets the requirement that a cookie with the specified name must exist and its value must not end with the specified substring. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
name
: The name of the cookie that must exist.value_suffix
: The substring that must not be at the end of the cookie value.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_matches
Sets the requirement that a cookie with a name matching the specified regex must exist and its value must match the specified regex. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
key_regex
: The regex pattern that the cookie name must match.value_regex
: The regex pattern that the cookie value must match.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.
cookie_count
Sets the requirement that a cookie with a name and value matching the specified regexes must appear a specified number of times in the HTTP request. Cookie parsing follows RFC-6265. Attention: Cookie names are case-sensitive.
Parameters
key_regex
: The regex pattern that the cookie name must match.value_regex
: The regex pattern that the cookie value must match.count
: The number of times a cookie with a matching name and value must appear.
Note: This function is only available when the
cookies
feature is enabled. This feature is enabled by default.
Example
Returns
The updated When
instance to allow method chaining for additional configuration.