pub enum Operation {
Eq(HeaderName, HeaderValue),
Exist(HeaderName),
In(HeaderName, Vec<HeaderValue>),
Contains(HeaderName, String),
Regex(HeaderName, Regex),
}Expand description
Matching operations for HTTP headers.
These operations can be used with both request and response headers.
§Variants
Eq: Exact match on header valueExist: Header presence check (any value)In: Match any of several valuesContains: Substring match within header valueRegex: Pattern match using regular expression
§Examples
use hitbox_http::predicates::header::Operation;
use http::header::CONTENT_TYPE;
// Match exact header value
let op = Operation::Eq(
CONTENT_TYPE,
"application/json".parse().unwrap(),
);
// Check header exists
let op = Operation::Exist(CONTENT_TYPE);
// Match substring in header value
let op = Operation::Contains(CONTENT_TYPE, "json".to_string());Using regex for complex patterns:
use hitbox_http::predicates::header::Operation;
use http::header::ACCEPT;
use regex::Regex;
// Match Accept headers containing version info
let op = Operation::Regex(
ACCEPT,
Regex::new(r"application/vnd\.api\+json; version=\d+").unwrap(),
);Variants§
Eq(HeaderName, HeaderValue)
Use when you need an exact match on a known header value.
Best for specific content types, authorization schemes, or cache directives.
Exist(HeaderName)
Use when presence of a header determines cacheability, regardless of value.
Best for checking optional headers like Authorization or custom API headers.
In(HeaderName, Vec<HeaderValue>)
Use when any of several values should trigger caching.
Best for allowing multiple content types or API versions.
Contains(HeaderName, String)
Use when matching partial values in complex headers.
Best for content types with parameters (e.g., "json" in application/json; charset=utf-8).
Regex(HeaderName, Regex)
Use when header values follow a pattern.
Best for version strings, custom formats, or extracting structured data.