Skip to main content

Method

Struct Method 

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

Source

pub fn new<E, T>(method: T) -> Result<Self, E>
where T: TryInto<Method, Error = 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>

Source

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§

Source§

impl<P: Debug> Debug for Method<P>

Source§

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

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

impl<P, ReqBody> Predicate for Method<P>
where P: Predicate<Subject = CacheableHttpRequest<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, request: 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 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<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> + Send + Sync>
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