diff --git a/examples/middleware-closure.rs b/examples/middleware-closure.rs new file mode 100644 index 000000000..0135bac9a --- /dev/null +++ b/examples/middleware-closure.rs @@ -0,0 +1,18 @@ +use actix_web::{middleware, web, App, HttpServer}; + +use futures::future; + +use actix_web_httpauth::middleware::HttpAuthentication; + +fn main() -> std::io::Result<()> { + HttpServer::new(|| { + let auth = HttpAuthentication::basic(|req, _credentials| future::ok(req)); + App::new() + .wrap(middleware::Logger::default()) + .wrap(auth) + .service(web::resource("/").to(|| "Test\r\n")) + }) + .bind("127.0.0.1:8080")? + .workers(1) + .run() +} diff --git a/src/middleware.rs b/src/middleware.rs index f03f26497..d9ce8c563 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -34,7 +34,7 @@ where impl HttpAuthentication where T: AuthExtractor, - F: FnMut(ServiceRequest, T) -> O, + F: Fn(ServiceRequest, T) -> O, O: IntoFuture, { /// Construct `HttpAuthentication` middleware @@ -50,7 +50,7 @@ where impl HttpAuthentication where - F: FnMut(ServiceRequest, basic::BasicAuth) -> O, + F: Fn(ServiceRequest, basic::BasicAuth) -> O, O: IntoFuture, { /// Construct `HttpAuthentication` middleware for the HTTP "Basic" @@ -86,7 +86,7 @@ where impl HttpAuthentication where - F: FnMut(ServiceRequest, bearer::BearerAuth) -> O, + F: Fn(ServiceRequest, bearer::BearerAuth) -> O, O: IntoFuture, { /// Construct `HttpAuthentication` middleware for the HTTP "Bearer"