1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use Body as HttpBody;
use crateBufferedBody;
/// Enables predicates and extractors to work uniformly with requests and responses.
///
/// This trait abstracts over the common pattern of decomposing an HTTP message into
/// its metadata (headers, status, method, etc.) and body, then reconstructing it.
/// Predicates that inspect the body use this to temporarily take ownership of the
/// body, examine it, and return a potentially modified subject.
///
/// # For Implementors
///
/// Implementations must ensure round-trip consistency: calling `from_parts` with
/// the result of `into_parts` must produce an equivalent subject.
///
/// ```
/// use hitbox_http::CacheableSubject;
///
/// fn round_trip<S: CacheableSubject>(subject: S) -> S {
/// let (parts, body) = subject.into_parts();
/// S::from_parts(parts, body)
/// // reconstructed should be equivalent to subject
/// }
/// ```
///
/// # For Callers
///
/// Use this trait when writing predicates or extractors that need to:
/// - Inspect the body without fully consuming it
/// - Pass the subject through a chain of operations
/// - Work generically with both requests and responses
///
/// # Caveats
///
/// After `into_parts`, the body may be in a different state than before. If a
/// predicate consumed bytes, the body transitions from `Passthrough` to `Partial`
/// or `Complete`. Callers must handle all [`BufferedBody`] states.