Struct ajars_actix_web::actix_web::middleware::DefaultHeaders [−][src]
pub struct DefaultHeaders { /* fields omitted */ }
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};
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
Constructs an empty DefaultHeaders
middleware.
pub fn header<K, V>(self, key: K, value: V) -> DefaultHeaders where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
pub fn header<K, V>(self, key: K, value: V) -> DefaultHeaders where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<Error>,
Adds a header to the default set.
Adds a default Content-Type header if response does not contain one.
Default is application/octet-stream
.
Trait Implementations
Returns the “default value” for a type. Read more
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
<S as Service<ServiceRequest>>::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
<S as Service<ServiceRequest>>::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.
pub fn new_transform(
&self,
service: S
) -> <DefaultHeaders as Transform<S, ServiceRequest>>::Future
pub fn new_transform(
&self,
service: S
) -> <DefaultHeaders as Transform<S, ServiceRequest>>::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
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self