1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-02-02 10:59:03 +01:00

Tighten HttpAuthentication::with_fn bound from FnMut to Fn. (#11)

* Tighten HttpAuthentication::with_fn bound from FnMut to Fn.
* Add middleware with closure example.
This commit is contained in:
Masaki Hara 2019-07-20 00:34:59 +09:00 committed by svartalf
parent 27a894cab7
commit 4eeb1d9599
2 changed files with 21 additions and 3 deletions

View File

@ -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()
}

View File

@ -34,7 +34,7 @@ where
impl<T, F, O> HttpAuthentication<T, F>
where
T: AuthExtractor,
F: FnMut(ServiceRequest, T) -> O,
F: Fn(ServiceRequest, T) -> O,
O: IntoFuture<Item = ServiceRequest, Error = Error>,
{
/// Construct `HttpAuthentication` middleware
@ -50,7 +50,7 @@ where
impl<F, O> HttpAuthentication<basic::BasicAuth, F>
where
F: FnMut(ServiceRequest, basic::BasicAuth) -> O,
F: Fn(ServiceRequest, basic::BasicAuth) -> O,
O: IntoFuture<Item = ServiceRequest, Error = Error>,
{
/// Construct `HttpAuthentication` middleware for the HTTP "Basic"
@ -86,7 +86,7 @@ where
impl<F, O> HttpAuthentication<bearer::BearerAuth, F>
where
F: FnMut(ServiceRequest, bearer::BearerAuth) -> O,
F: Fn(ServiceRequest, bearer::BearerAuth) -> O,
O: IntoFuture<Item = ServiceRequest, Error = Error>,
{
/// Construct `HttpAuthentication` middleware for the HTTP "Bearer"