Skip to main content

hitbox_http/predicates/request/
mod.rs

1//! Request predicates for cache eligibility.
2//!
3//! These predicates evaluate incoming HTTP requests to determine if a cache
4//! lookup should be attempted.
5//!
6//! # Examples
7//!
8//! Cache only GET and HEAD requests:
9//!
10//! ```
11//! use hitbox_http::predicates::request::Method;
12//!
13//! # use bytes::Bytes;
14//! # use http_body_util::Empty;
15//! # use hitbox::Neutral;
16//! # use hitbox_http::CacheableHttpRequest;
17//! # type Subject = CacheableHttpRequest<Empty<Bytes>>;
18//! // Single method
19//! let predicate = Method::new(http::Method::GET).unwrap();
20//! # let _: &Method<Neutral<Subject>> = &predicate;
21//!
22//! // Multiple methods
23//! let predicate = Method::new_in(
24//!     Neutral::new(),
25//!     vec![http::Method::GET, http::Method::HEAD],
26//! );
27//! # let _: &Method<Neutral<Subject>> = &predicate;
28//! ```
29//!
30//! Skip cache for requests with `Cache-Control: no-cache`:
31//!
32//! ```
33//! use hitbox::predicate::PredicateExt;
34//! use hitbox_http::predicates::header::{Header, Operation};
35//!
36//! # use bytes::Bytes;
37//! # use http_body_util::Empty;
38//! # use hitbox::Neutral;
39//! # use hitbox_http::CacheableHttpRequest;
40//! # type Subject = CacheableHttpRequest<Empty<Bytes>>;
41//! let predicate = Header::new(Operation::Contains(
42//!     http::header::CACHE_CONTROL,
43//!     "no-cache".to_string(),
44//! ));
45//! # let _: &Header<Neutral<Subject>> = &predicate;
46//! let predicate = predicate.not();
47//! ```
48
49pub mod body;
50pub mod header;
51/// HTTP method predicates for cache eligibility.
52pub mod method;
53pub mod path;
54pub mod query;
55
56pub use body::{Body, BodyPredicate};
57pub use header::{Header, HeaderPredicate};
58pub use method::{Method, MethodPredicate};
59pub use path::{Path, PathPredicate};
60pub use query::{Query, QueryPredicate};