pub struct StatusCode<P> { /* private fields */ }Expand description
A predicate that matches responses by HTTP status code.
§Type Parameters
P- The inner predicate to chain with. UseStatusCode::newto start a new predicate chain (usesNeutralinternally), or use theStatusCodePredicateextension trait to chain onto an existing predicate.
§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>>
impl<S> StatusCode<Neutral<S>>
Sourcepub fn new(status_code: StatusCode) -> Self
pub fn new(status_code: StatusCode) -> Self
Creates a predicate matching a specific status code.
Source§impl<P> StatusCode<P>
impl<P> StatusCode<P>
Sourcepub fn new_in(inner: P, codes: Vec<StatusCode>) -> Self
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],
);Sourcepub fn new_range(inner: P, start: StatusCode, end: StatusCode) -> Self
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(),
);Sourcepub fn new_class(inner: P, class: StatusClass) -> Self
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);