Expand description
Predicates for determining HTTP request and response cacheability.
Predicates evaluate HTTP messages and return Cacheable or NonCacheable.
They can be combined using logical operators from the conditions module.
§Request vs Response Predicates
- Request predicates decide whether to attempt a cache lookup
- Response predicates decide whether to store a response in cache
§Available Predicates
§Request Predicates (request module)
| Predicate | Description |
|---|---|
request::Method | Match by HTTP method |
request::Path | Match by URL path pattern |
request::Header | Match by request header |
request::Query | Match by query parameter |
request::Body | Match by request body content |
§Response Predicates (response module)
| Predicate | Description |
|---|---|
response::StatusCode | Match by status code or class |
response::Header | Match by response header |
response::Body | Match by response body content |
§Combining Predicates
Use PredicateExt to combine predicates:
use hitbox::predicate::PredicateExt;
use hitbox_http::predicates::request::Method;
use hitbox_http::predicates::header::{Header, Operation};
// Cache GET requests without Cache-Control: no-cache
let predicate = Method::new(http::Method::GET).unwrap();
let predicate = predicate.and(
Header::new(Operation::Contains(
http::header::CACHE_CONTROL,
"no-cache".to_string(),
)).not()
);Modules§
- body
- Body content predicates for cache decisions.
- conditions
- Logical combinators for predicates.
- header
- Header matching predicates.
- request
- Request predicates for cache eligibility.
- response
- Response predicates for cache storage decisions.
- version
- HTTP version matching predicates.
Type Aliases§
- Neutral
Request Predicate - A neutral predicate for HTTP requests that always returns
Cacheable. - Neutral
Response Predicate - A neutral predicate for HTTP responses that always returns
Cacheable.