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§
source§impl 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§
source§impl Clone for DefaultHeaders
impl Clone for DefaultHeaders
source§fn clone(&self) -> DefaultHeaders
fn clone(&self) -> DefaultHeaders
Returns a copy of the value. Read more
1.0.0 · 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§fn default() -> DefaultHeaders
fn default() -> DefaultHeaders
Returns the “default value” for a type. Read more
source§impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders
§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
§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.
source§fn 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 Freeze for DefaultHeaders
impl RefUnwindSafe for DefaultHeaders
impl !Send for DefaultHeaders
impl !Sync for DefaultHeaders
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)