Skip to main content

hitbox_http/predicates/body/
mod.rs

1//! Body content predicates for cache decisions.
2//!
3//! These predicates evaluate the body content of requests or responses.
4//!
5//! # Operations
6//!
7//! | Operation | Description |
8//! |-----------|-------------|
9//! | [`Operation::Limit`] | Cache only if body size is within limit |
10//! | [`Operation::Plain`] | Match body as plain text (contains, regex, etc.) |
11//! | [`Operation::Jq`] | Evaluate body as JSON using JQ expressions |
12//!
13//! # Caveats
14//!
15//! Body predicates consume bytes from the stream. After evaluation:
16//! - The body transitions to [`BufferedBody::Partial`] or [`BufferedBody::Complete`]
17//! - Subsequent predicates receive the modified body state
18//! - Order your predicates to minimize body consumption
19//!
20//! # Examples
21//!
22//! Only cache responses with non-empty JSON arrays:
23//!
24//! ```
25//! use hitbox_http::predicates::body::{Operation, JqExpression, JqOperation};
26//!
27//! let op = Operation::Jq {
28//!     filter: JqExpression::compile(".items | length > 0").unwrap(),
29//!     operation: JqOperation::Eq(serde_json::Value::Bool(true)),
30//! };
31//! ```
32//!
33//! [`BufferedBody::Partial`]: crate::BufferedBody::Partial
34//! [`BufferedBody::Complete`]: crate::BufferedBody::Complete
35
36mod jq;
37mod operation;
38mod plain;
39mod predicate;
40
41pub use jq::{JqExpression, JqOperation};
42pub use operation::Operation;
43pub use plain::PlainOperation;
44pub use predicate::{Body, BodyPredicate};