Skip to main content

CustomResponder

Struct CustomResponder 

Source
pub struct CustomResponder<T: Responder<St>, St: State> { /* private fields */ }
Expand description

Allows to override status code and headers for a responder.

Implementations§

Source§

impl<T: Responder<St>, St: State> CustomResponder<T, St>

Source

pub fn with_status(self, status: StatusCode) -> Self

Override a status code for the Responder’s response.

The status replaces whatever the inner responder produced, including error statuses rendered by a Result error. Use result.map(|v| v.with_status(status)) to change only the success status; see Responder::with_status().

use ntex::http::StatusCode;
use ntex::web::{HttpRequest, Responder};

fn index(req: HttpRequest) -> impl Responder {
    "Welcome!".with_status(StatusCode::OK)
}
Source

pub fn set_header<K, V>(self, key: K, value: V) -> Self

Sets a header on the Responder’s response.

Replaces values with the same name, both those produced by the inner responder and those added by earlier set_header() or with_header() calls. An invalid name or value makes the response 500 Internal Server Error.

use ntex::http::StatusCode;
use ntex::web::{HttpRequest, Responder};

fn index(req: HttpRequest) -> impl Responder {
    "Created"
        .with_status(StatusCode::CREATED)
        .set_header("x-version", "1.2.3")
}
Source

pub fn with_header<K, V>(self, key: K, value: V) -> Self

Adds a header value to the Responder’s response.

Keeps values added by earlier with_header() or set_header() calls, so one name can carry several values. Values with the same name produced by the inner responder are still replaced. An invalid name or value makes the response 500 Internal Server Error.

use ntex::web::{HttpRequest, Responder};

fn index(req: HttpRequest) -> impl Responder {
    "Welcome!"
        .with_header("vary", "accept")
        .with_header("vary", "accept-encoding")
}

Trait Implementations§

Source§

impl<T: Responder<St>, St: State> Debug for CustomResponder<T, St>

Source§

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

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

impl<T: Responder<St>, St: State> Responder<St> for CustomResponder<T, St>

Source§

async fn respond_to(self, st: &St, req: &HttpRequest) -> Response

Builds an HTTP response from this value.
Source§

fn with_status(self, status: StatusCode) -> CustomResponder<Self, St>
where Self: Sized,

Replaces the status code produced by this responder. Read more
Source§

fn with_header<K, V>(self, key: K, value: V) -> CustomResponder<Self, St>

Sets a header on the response produced by this responder. Read more

Auto Trait Implementations§

§

impl<T, St> Freeze for CustomResponder<T, St>
where T: Freeze,

§

impl<T, St> RefUnwindSafe for CustomResponder<T, St>

§

impl<T, St> Send for CustomResponder<T, St>
where T: Send, St: Send,

§

impl<T, St> Sync for CustomResponder<T, St>
where T: Sync, St: Sync,

§

impl<T, St> Unpin for CustomResponder<T, St>
where T: Unpin, St: Unpin,

§

impl<T, St> UnsafeUnpin for CustomResponder<T, St>
where T: UnsafeUnpin,

§

impl<T, St> UnwindSafe for CustomResponder<T, St>
where T: UnwindSafe, St: 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V