Struct afire::extension::Head

source ยท
pub struct Head { /* private fields */ }
Expand description

Middleware to add support for the HTTP HEAD method. It does this by changing the method to GET and adding a special header (afire::head). Once the response is processed by the normal route handler, the middleware will check if the header is present. If it is, any body data will be discarded and the [Content-Length] header will be added, if it is not already present. On static responses, the length is already known, but with streaming responses, the stream will be read to the end to get the length (by default).

Implementationsยง

sourceยง

impl Head

source

pub fn new() -> Self

Create a new instance of the middleware.

source

pub fn streaming(self, streaming: bool) -> Self

Set whether to add the Content-Length header to streaming responses.

Example
let head = Head::new().streaming(false);

Trait Implementationsยง

sourceยง

impl Default for Head

sourceยง

fn default() -> Self

Returns the โ€œdefault valueโ€ for a type. Read more
sourceยง

impl Middleware for Head

sourceยง

fn pre(&self, req: &mut Request) -> MiddleResult

Middleware to run Before Routes
sourceยง

fn post(&self, req: &Request, res: &mut Response) -> MiddleResult

Middleware to run After Routes
sourceยง

fn pre_raw(&self, req: &mut Result<Request>) -> MiddleResult

Middleware to run before routes. Because this is the raw version of Middleware::pre, it is passed a Result. The default implementation calls Middleware::pre if the Result is Ok.
sourceยง

fn post_raw( &self, req: Result<Rc<Request>>, res: &mut Result<Response> ) -> MiddleResult

Middleware to run after routes. Because this is the raw version of Middleware::post, it is passed a Result. The default implementation calls Middleware::post if the Result is Ok.
sourceยง

fn end_raw(&self, req: &Result<Request>, res: &Result<Response>)

Middleware to run after the response has been handled. Because this is the raw version of Middleware::end, it is passed a Result. The default implementation calls Middleware::end if the Result is Ok.
sourceยง

fn end(&self, _req: &Request, _res: &Response)

Middleware ot run after the response has been handled
sourceยง

fn attach<State>(self, server: &mut Server<State>)where Self: 'static + Send + Sync + Sized, State: 'static + Send + Sync,

Attach Middleware to a Server. If you want to get a reference to the serverโ€™s state in your middleware state, you should override this method.

Auto Trait Implementationsยง

Blanket Implementationsยง

sourceยง

impl<T> Any for Twhere T: 'static + ?Sized,

sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
sourceยง

impl<T> Borrow<T> for Twhere T: ?Sized,

sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
sourceยง

impl<T> BorrowMut<T> for Twhere 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<T, U> Into<U> for Twhere 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<T, U> TryFrom<U> for Twhere U: Into<T>,

ยง

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 Twhere U: TryFrom<T>,

ยง

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.