Skip to main content

Middleware

Trait Middleware 

Source
pub trait Middleware: Send {
    // Required methods
    fn is_method_get_head(&self) -> bool;
    fn policy(&self, response: &HttpResponse) -> Result<CachePolicy>;
    fn policy_with_options(
        &self,
        response: &HttpResponse,
        options: CacheOptions,
    ) -> Result<CachePolicy>;
    fn update_headers(&mut self, parts: &Parts) -> Result<()>;
    fn force_no_cache(&mut self) -> Result<()>;
    fn parts(&self) -> Result<Parts>;
    fn url(&self) -> Result<Url>;
    fn method(&self) -> Result<String>;
    fn remote_fetch(
        &mut self,
    ) -> impl Future<Output = Result<HttpResponse>> + Send;

    // Provided method
    fn overridden_cache_mode(&self) -> Option<CacheMode> { ... }
}
Expand description

Describes the functionality required for interfacing with HTTP client middleware

Required Methods§

Source

fn is_method_get_head(&self) -> bool

Determines if the request method is either GET or HEAD

Source

fn policy(&self, response: &HttpResponse) -> Result<CachePolicy>

Returns a new cache policy with default options

Source

fn policy_with_options( &self, response: &HttpResponse, options: CacheOptions, ) -> Result<CachePolicy>

Returns a new cache policy with custom options

Source

fn update_headers(&mut self, parts: &Parts) -> Result<()>

Attempts to update the request headers with the passed http::request::Parts

Source

fn force_no_cache(&mut self) -> Result<()>

Attempts to force the “no-cache” directive on the request

Source

fn parts(&self) -> Result<Parts>

Attempts to construct http::request::Parts from the request

Source

fn url(&self) -> Result<Url>

Attempts to determine the requested url

Source

fn method(&self) -> Result<String>

Attempts to determine the request method

Source

fn remote_fetch(&mut self) -> impl Future<Output = Result<HttpResponse>> + Send

Attempts to fetch an upstream resource and return an HttpResponse

Provided Methods§

Source

fn overridden_cache_mode(&self) -> Option<CacheMode>

Allows the cache mode to be overridden.

This overrides any cache mode set in the configuration, including cache_mode_fn.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§