pub struct Body<P> { /* private fields */ }Expand description
A predicate that matches HTTP bodies against an Operation.
Works with both requests and responses through the CacheableSubject trait.
Chain with other predicates using the builder pattern.
§Type Parameters
P- The inner predicate to chain with. UseBody::newto start a new predicate chain (usesNeutralinternally), or use theBodyPredicateextension trait to chain onto an existing predicate.
§Examples
use hitbox_http::predicates::body::{Body, Operation};
// Only cache responses smaller than 1MB
let predicate = Body::new(Operation::Limit { bytes: 1024 * 1024 });§Caveats
Body predicates consume bytes from the stream. The body is buffered during
evaluation and returned in a BufferedBody state.
Order body predicates last in a chain when possible.
Implementations§
Source§impl<S> Body<Neutral<S>>
impl<S> Body<Neutral<S>>
Sourcepub fn new(operation: Operation) -> Self
pub fn new(operation: Operation) -> Self
Creates a predicate that matches body content against the operation.
Returns Cacheable when
the body satisfies the operation, NonCacheable otherwise.
Chain onto existing predicates using BodyPredicate::body instead
if you already have a predicate chain.
Trait Implementations§
Source§impl<P> Predicate for Body<P>where
P: Predicate + Send + Sync,
P::Subject: CacheableSubject + Send,
<P::Subject as CacheableSubject>::Body: Send + Unpin + 'static,
<P::Subject as CacheableSubject>::Parts: Send,
<<P::Subject as CacheableSubject>::Body as HttpBody>::Error: Send,
<<P::Subject as CacheableSubject>::Body as HttpBody>::Data: Send,
impl<P> Predicate for Body<P>where
P: Predicate + Send + Sync,
P::Subject: CacheableSubject + Send,
<P::Subject as CacheableSubject>::Body: Send + Unpin + 'static,
<P::Subject as CacheableSubject>::Parts: Send,
<<P::Subject as CacheableSubject>::Body as HttpBody>::Error: Send,
<<P::Subject as CacheableSubject>::Body as HttpBody>::Data: Send,
Auto Trait Implementations§
impl<P> !Freeze for Body<P>
impl<P> RefUnwindSafe for Body<P>where
P: RefUnwindSafe,
impl<P> Send for Body<P>where
P: Send,
impl<P> Sync for Body<P>where
P: Sync,
impl<P> Unpin for Body<P>where
P: Unpin,
impl<P> UnwindSafe for Body<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<P> BodyPredicate for Pwhere
P: Predicate,
impl<P> BodyPredicate for Pwhere
P: Predicate,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<P> HeaderPredicate for Pwhere
P: Predicate,
impl<P> HeaderPredicate for Pwhere
P: Predicate,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<P> MethodPredicate for Pwhere
P: Predicate,
impl<P> MethodPredicate for Pwhere
P: Predicate,
Source§impl<P> PathPredicate for Pwhere
P: Predicate,
impl<P> PathPredicate for Pwhere
P: Predicate,
Source§impl<T> PredicateExt for Twhere
T: Predicate,
impl<T> PredicateExt for Twhere
T: Predicate,
Source§impl<P> QueryPredicate for Pwhere
P: Predicate,
impl<P> QueryPredicate for Pwhere
P: Predicate,
Source§impl<P> StatusCodePredicate for Pwhere
P: Predicate,
impl<P> StatusCodePredicate for Pwhere
P: Predicate,
Source§fn status_code(self, status_code: StatusCode) -> StatusCode<P>
fn status_code(self, status_code: StatusCode) -> StatusCode<P>
Matches an exact status code.
Source§fn status_code_in(self, codes: Vec<StatusCode>) -> StatusCode<P>
fn status_code_in(self, codes: Vec<StatusCode>) -> StatusCode<P>
Matches any of the specified status codes.
Source§fn status_code_range(self, start: StatusCode, end: StatusCode) -> StatusCode<P>
fn status_code_range(self, start: StatusCode, end: StatusCode) -> StatusCode<P>
Matches status codes within a range (inclusive).
Source§fn status_code_class(self, class: StatusClass) -> StatusCode<P>
fn status_code_class(self, class: StatusClass) -> StatusCode<P>
Matches all status codes in a class (e.g., all 2xx).
Source§impl<P> VersionPredicate for Pwhere
P: Predicate,
impl<P> VersionPredicate for Pwhere
P: Predicate,
Source§fn version(self, operation: Operation) -> HttpVersion<P>
fn version(self, operation: Operation) -> HttpVersion<P>
Adds a version match to this predicate chain.