pub struct Method<P> { /* private fields */ }Expand description
A predicate that matches requests by HTTP method.
§Type Parameters
P- The inner predicate to chain with. UseMethod::newto start a new predicate chain (usesNeutralinternally), or use theMethodPredicateextension trait to chain onto an existing predicate.
§Examples
Match only GET requests:
use hitbox_http::predicates::request::Method;
let predicate = Method::new(http::Method::GET).unwrap();Match GET or HEAD requests (using the builder pattern):
use hitbox::Neutral;
use hitbox_http::predicates::request::Method;
let predicate = Method::new_in(
Neutral::new(),
vec![http::Method::GET, http::Method::HEAD],
);Implementations§
Source§impl<S> Method<Neutral<S>>
impl<S> Method<Neutral<S>>
Sourcepub fn new<E, T>(method: T) -> Result<Self, E>
pub fn new<E, T>(method: T) -> Result<Self, E>
Creates a predicate matching requests with the specified HTTP method.
Returns Cacheable when
the request method matches, NonCacheable otherwise.
§Errors
Returns an error if method cannot be converted to http::Method.
When passing http::Method directly, this is infallible.
When passing a string, returns http::method::InvalidMethod if the
string is not a valid HTTP method.
Source§impl<P> Method<P>
impl<P> Method<P>
Sourcepub fn new_in(inner: P, methods: Vec<Method>) -> Self
pub fn new_in(inner: P, methods: Vec<Method>) -> Self
Creates a predicate matching requests with any of the specified HTTP methods.
Returns Cacheable when
the request method is in the provided list, NonCacheable otherwise.
Use this for caching strategies that apply to multiple methods (e.g., GET and HEAD).
Trait Implementations§
Auto Trait Implementations§
impl<P> Freeze for Method<P>where
P: Freeze,
impl<P> RefUnwindSafe for Method<P>where
P: RefUnwindSafe,
impl<P> Send for Method<P>where
P: Send,
impl<P> Sync for Method<P>where
P: Sync,
impl<P> Unpin for Method<P>where
P: Unpin,
impl<P> UnwindSafe for Method<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.