Skip to main content

Module predicates

Module predicates 

Source
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)

PredicateDescription
request::MethodMatch by HTTP method
request::PathMatch by URL path pattern
request::HeaderMatch by request header
request::QueryMatch by query parameter
request::BodyMatch by request body content

§Response Predicates (response module)

PredicateDescription
response::StatusCodeMatch by status code or class
response::HeaderMatch by response header
response::BodyMatch 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§

NeutralRequestPredicate
A neutral predicate for HTTP requests that always returns Cacheable.
NeutralResponsePredicate
A neutral predicate for HTTP responses that always returns Cacheable.