Skip to main content

StatusCode

Struct StatusCode 

Source
pub struct StatusCode<P> { /* private fields */ }
Expand description

A predicate that matches responses by HTTP status code.

§Type Parameters

§Examples

Match only 200 OK responses:

use hitbox_http::predicates::response::StatusCode;

let predicate = StatusCode::new(http::StatusCode::OK);

Chain with body predicate:

use hitbox_http::predicates::response::StatusCode;
use hitbox_http::predicates::body::{BodyPredicate, Operation as BodyOperation, PlainOperation};

let predicate = StatusCode::new(http::StatusCode::OK)
    .body(BodyOperation::Plain(PlainOperation::Contains("success".into())));

Implementations§

Source§

impl<S> StatusCode<Neutral<S>>

Source

pub fn new(status_code: StatusCode) -> Self

Creates a predicate matching a specific status code.

Source§

impl<P> StatusCode<P>

Source

pub fn new_in(inner: P, codes: Vec<StatusCode>) -> Self

Creates a predicate matching any of the specified status codes.

Returns Cacheable when the response status code is in the provided list.

Use this for caching multiple specific status codes (e.g., 200 and 304).

§Examples
use hitbox::Neutral;
use hitbox_http::predicates::response::StatusCode;

// Cache 200 OK and 304 Not Modified responses
let predicate = StatusCode::new_in(
    Neutral::new(),
    vec![http::StatusCode::OK, http::StatusCode::NOT_MODIFIED],
);
Source

pub fn new_range(inner: P, start: StatusCode, end: StatusCode) -> Self

Creates a predicate matching status codes within a range (inclusive).

Returns Cacheable when the response status code is between start and end (inclusive).

Use this for custom status code ranges not covered by StatusClass.

§Examples
use hitbox::Neutral;
use hitbox_http::predicates::response::StatusCode;

// Cache responses with status codes 200-299 and 304
let predicate = StatusCode::new_range(
    Neutral::new(),
    http::StatusCode::OK,
    http::StatusCode::from_u16(299).unwrap(),
);
Source

pub fn new_class(inner: P, class: StatusClass) -> Self

Creates a predicate matching all status codes in a class.

Returns Cacheable when the response status code belongs to the specified class (e.g., all 2xx).

Use this for broad caching rules like “cache all successful responses”.

§Examples
use hitbox::Neutral;
use hitbox_http::predicates::response::{StatusCode, StatusClass};

// Cache all successful (2xx) responses
let predicate = StatusCode::new_class(Neutral::new(), StatusClass::Success);

Trait Implementations§

Source§

impl<P: Debug> Debug for StatusCode<P>

Source§

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

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

impl<P, ReqBody> Predicate for StatusCode<P>
where P: Predicate<Subject = CacheableHttpResponse<ReqBody>> + Send + Sync, ReqBody: Body + Send + 'static, ReqBody::Error: Send,

Source§

type Subject = <P as Predicate>::Subject

The type being evaluated by this predicate.
Source§

fn check<'life0, 'async_trait>( &'life0 self, response: 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 StatusCode<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for StatusCode<P>
where P: RefUnwindSafe,

§

impl<P> Send for StatusCode<P>
where P: Send,

§

impl<P> Sync for StatusCode<P>
where P: Sync,

§

impl<P> Unpin for StatusCode<P>
where P: Unpin,

§

impl<P> UnwindSafe for StatusCode<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