pub struct DefaultHeaders { /* private fields */ }Expand description
Middleware for setting default response headers.
This middleware does not set header if response headers already contains it.
use ntex::http;
use ntex::web::{self, middleware, App, HttpResponse};
fn main() {
let app = App::default()
.middleware(middleware::DefaultHeaders::new().header("X-Version", "0.2"))
.service(
web::resource("/test")
.route(web::get().to(async || { HttpResponse::Ok() }))
.route(web::method(http::Method::HEAD).to(async || { HttpResponse::MethodNotAllowed() }))
);
}Implementations§
Source§impl DefaultHeaders
impl DefaultHeaders
Sourcepub fn new() -> DefaultHeaders
pub fn new() -> DefaultHeaders
Construct DefaultHeaders middleware.
Sourcepub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn header<K, V>(self, key: K, value: V) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Set a header.
Sourcepub fn content_type(self) -> Self
pub fn content_type(self) -> Self
Set CONTENT-TYPE header if response does not contain this header.
The header is set to application/octet-stream.
Trait Implementations§
Source§impl Clone for DefaultHeaders
impl Clone for DefaultHeaders
Source§fn clone(&self) -> DefaultHeaders
fn clone(&self) -> DefaultHeaders
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for DefaultHeaders
impl Debug for DefaultHeaders
Source§impl Default for DefaultHeaders
impl Default for DefaultHeaders
Source§impl<S, St> Middleware<S, St> for DefaultHeaders
impl<S, St> Middleware<S, St> for DefaultHeaders
Source§fn create(&self, _: &St, service: S) -> Self::Service
fn create(&self, _: &St, service: S) -> Self::Service
Creates and returns a new middleware service.
Source§fn apply_to<Sf, Req>(
self,
factory: Sf,
) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
fn apply_to<Sf, Req>( self, factory: Sf, ) -> ServiceChainFactory<ApplyMiddleware<Self, Sf>, St, Req>
Creates a service factory that instantiates a service and applies
the current middleware to it. Read more
Auto Trait Implementations§
impl !Send for DefaultHeaders
impl !Sync for DefaultHeaders
impl Freeze for DefaultHeaders
impl RefUnwindSafe for DefaultHeaders
impl Unpin for DefaultHeaders
impl UnsafeUnpin for DefaultHeaders
impl UnwindSafe for DefaultHeaders
Blanket Implementations§
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