hitbox_http/predicates/response/mod.rs
1//! Response predicates for cache storage decisions.
2//!
3//! These predicates evaluate HTTP responses to determine if they should be
4//! stored in the cache.
5//!
6//! # Examples
7//!
8//! Cache only successful responses:
9//!
10//! ```
11//! use hitbox_http::predicates::response::{StatusCode, StatusClass};
12//!
13//! # use bytes::Bytes;
14//! # use http_body_util::Empty;
15//! # use hitbox::Neutral;
16//! # use hitbox_http::CacheableHttpResponse;
17//! # type Subject = CacheableHttpResponse<Empty<Bytes>>;
18//! // Match 2xx status codes
19//! let predicate = StatusCode::new(http::StatusCode::OK);
20//! # let _: &StatusCode<Neutral<Subject>> = &predicate;
21//! // Or match the entire success class
22//! let predicate = StatusCode::new_class(Neutral::new(), StatusClass::Success);
23//! # let _: &StatusCode<Neutral<Subject>> = &predicate;
24//! ```
25//!
26//! Cache responses with non-empty JSON arrays:
27//!
28//! ```
29//! use hitbox_http::predicates::response::{Body, Operation, JqExpression, JqOperation};
30//!
31//! # use bytes::Bytes;
32//! # use http_body_util::Empty;
33//! # use hitbox::Neutral;
34//! # use hitbox_http::CacheableHttpResponse;
35//! # type Subject = CacheableHttpResponse<Empty<Bytes>>;
36//! let predicate = Body::new(Operation::Jq {
37//! filter: JqExpression::compile(".items | length > 0").unwrap(),
38//! operation: JqOperation::Eq(serde_json::Value::Bool(true)),
39//! });
40//! # let _: &Body<Neutral<Subject>> = &predicate;
41//! ```
42
43pub mod body;
44pub mod header;
45/// HTTP status code predicates for cache storage.
46pub mod status;
47
48pub use body::{Body, BodyPredicate, JqFilter};
49pub use header::{Header, HeaderPredicate};
50pub use status::{StatusClass, StatusCode, StatusCodePredicate};
51
52// Re-export shared body types for convenience
53pub use crate::predicates::body::{JqExpression, JqOperation, Operation, PlainOperation};