Crate actix_optional_middleware[−][src]
Expand description
use std::rc::Rc;
use actix_optional_middleware::{Group, Dummy};
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
use actix_web::middleware::DefaultHeaders;
use actix_web::{web, body::BoxBody, App, Error, HttpServer, Responder, get};
#[get("/test", wrap = "get_group_middleware()")]
async fn h1() -> impl Responder {
"Handler 1"
}
// flip this value to see dummy in action
const ACTIVE: bool = true;
fn get_group_middleware<S>() -> Group<Dummy, DefaultHeaders, S>
where
S: Service<ServiceRequest, Response = ServiceResponse<BoxBody>, Error = Error> + 'static,
{
if ACTIVE {
Group::Real(Rc::new(DefaultHeaders::new()
.header("Permissions-Policy", "interest-cohort=()"
)))
} else {
Group::default()
}
}
Structs
Dummy Middleware: it simply forwards the request without operating on it
Dummy Middleware: it simply forwards the request without operating on it
Enums
Collection datatype that encapsulates dummy and real middlewares