Struct actix_web::middleware::DefaultHeaders
source · [−]pub struct DefaultHeaders { /* private fields */ }
Expand description
Middleware for setting default response headers.
Headers with the same key that are already set in a response will not be overwritten.
Examples
use actix_web::{web, http, middleware, App, HttpResponse};
let app = App::new()
.wrap(middleware::DefaultHeaders::new().add(("X-Version", "0.2")))
.service(
web::resource("/test")
.route(web::get().to(|| HttpResponse::Ok()))
.route(web::method(http::Method::HEAD).to(|| HttpResponse::MethodNotAllowed()))
);
Implementations
sourceimpl DefaultHeaders
impl DefaultHeaders
sourcepub fn new() -> DefaultHeaders
pub fn new() -> DefaultHeaders
Constructs an empty DefaultHeaders
middleware.
sourcepub fn add(self, header: impl TryIntoHeaderPair) -> Self
pub fn add(self, header: impl TryIntoHeaderPair) -> Self
sourcepub fn add_content_type(self) -> Self
pub fn add_content_type(self) -> Self
Adds a default Content-Type header if response does not contain one.
Default is application/octet-stream
.
Trait Implementations
sourceimpl Clone for DefaultHeaders
impl Clone for DefaultHeaders
sourcefn clone(&self) -> DefaultHeaders
fn clone(&self) -> DefaultHeaders
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for DefaultHeaders
impl Debug for DefaultHeaders
sourceimpl Default for DefaultHeaders
impl Default for DefaultHeaders
sourcefn default() -> DefaultHeaders
fn default() -> DefaultHeaders
Returns the “default value” for a type. Read more
sourceimpl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
type Transform = DefaultHeadersMiddleware<S>
type Transform = DefaultHeadersMiddleware<S>
The TransformService
value created by this factory
type Future = Ready<Result<<DefaultHeaders as Transform<S, ServiceRequest>>::Transform, <DefaultHeaders as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<DefaultHeaders as Transform<S, ServiceRequest>>::Transform, <DefaultHeaders as Transform<S, ServiceRequest>>::InitError>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more