Skip to main content

Body

Struct Body 

Source
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. Use Body::new to start a new predicate chain (uses Neutral internally), or use the BodyPredicate extension 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>>

Source

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: Debug> Debug for Body<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P> Predicate for Body<P>

Source§

type Subject = <P as Predicate>::Subject

The type being evaluated by this predicate.
Source§

fn check<'life0, 'async_trait>( &'life0 self, subject: Self::Subject, ) -> Pin<Box<dyn Future<Output = PredicateResult<Self::Subject>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Evaluate whether the subject should be cached. Read more

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<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<P> BodyPredicate for P
where P: Predicate,

Source§

fn body(self, operation: Operation) -> Body<P>

Adds a body matching operation to this predicate chain.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<P> HeaderPredicate for P
where P: Predicate,

Source§

fn header(self, operation: Operation) -> Header<P>

Adds a header matching operation to this predicate chain.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P> MethodPredicate for P
where P: Predicate,

Source§

fn method(self, method: Method) -> Method<P>

Adds an HTTP method match to this predicate chain.
Source§

impl<P> PathPredicate for P
where P: Predicate,

Source§

fn path(self, resource: String) -> Path<P>

Adds a path pattern match to this predicate chain. Read more
Source§

impl<T> PredicateExt for T
where T: Predicate,

Source§

fn and<R>(self, right: R) -> And<Self, R>
where R: Predicate<Subject = Self::Subject>,

Combines this predicate with another using AND logic. Read more
Source§

fn or<R>(self, right: R) -> Or<Self, R>
where R: Predicate<Subject = Self::Subject>,

Combines this predicate with another using OR logic. Read more
Source§

fn not(self) -> Not<Self>

Inverts this predicate’s result. Read more
Source§

fn boxed(self) -> Box<dyn Predicate<Subject = Self::Subject> + Sync + Send>
where Self: Send + Sync + 'static,

Boxes this predicate into a trait object. Read more
Source§

impl<P> QueryPredicate for P
where P: Predicate,

Source§

fn query(self, operation: Operation) -> Query<P>

Adds a query parameter match to this predicate chain.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<P> StatusCodePredicate for P
where P: Predicate,

Source§

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>

Matches any of the specified status codes.
Source§

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>

Matches all status codes in a class (e.g., all 2xx).
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<P> VersionPredicate for P
where P: Predicate,

Source§

fn version(self, operation: Operation) -> HttpVersion<P>

Adds a version match to this predicate chain.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more