Struct actix_web::middleware::DefaultHeaders [−][src]
pub struct DefaultHeaders { /* fields omitted */ }
Expand description
Middleware
for setting default response headers.
This middleware does not set header if response headers already contains it.
use actix_web::{web, http, middleware, App, HttpResponse};
fn main() {
let app = App::new()
.wrap(middleware::DefaultHeaders::new().header("X-Version", "0.2"))
.service(
web::resource("/test")
.route(web::get().to(|| HttpResponse::Ok()))
.route(web::method(http::Method::HEAD).to(|| HttpResponse::MethodNotAllowed()))
);
}
Implementations
Construct DefaultHeaders
middleware.
pub fn header<K, V>(self, key: K, value: V) -> Self where
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) -> Self where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Set a header.
Set CONTENT-TYPE header if response does not contain this header.
Trait Implementations
impl<S, B> Transform<S> for DefaultHeaders where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
impl<S, B> Transform<S> for DefaultHeaders where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Request = ServiceRequest
type Request = ServiceRequest
Requests handled by the service.
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses given by the service.
type Transform = DefaultHeadersMiddleware<S>
type Transform = DefaultHeadersMiddleware<S>
The TransformService
value created by this factory
Creates and returns a new Transform component, asynchronously
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E> where
F: Fn(Self::InitError) -> E + Clone,
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E> where
F: Fn(Self::InitError) -> E + Clone,
Map this transforms’s factory error to a different error, returning a new transform service factory. Read more
Auto Trait Implementations
impl RefUnwindSafe for DefaultHeaders
impl !Send for DefaultHeaders
impl !Sync for DefaultHeaders
impl Unpin for DefaultHeaders
impl UnwindSafe for DefaultHeaders
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more