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:
parent
27a894cab7
commit
4eeb1d9599
18
examples/middleware-closure.rs
Normal file
18
examples/middleware-closure.rs
Normal 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()
|
||||||
|
}
|
@ -34,7 +34,7 @@ where
|
|||||||
impl<T, F, O> HttpAuthentication<T, F>
|
impl<T, F, O> HttpAuthentication<T, F>
|
||||||
where
|
where
|
||||||
T: AuthExtractor,
|
T: AuthExtractor,
|
||||||
F: FnMut(ServiceRequest, T) -> O,
|
F: Fn(ServiceRequest, T) -> O,
|
||||||
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
||||||
{
|
{
|
||||||
/// Construct `HttpAuthentication` middleware
|
/// Construct `HttpAuthentication` middleware
|
||||||
@ -50,7 +50,7 @@ where
|
|||||||
|
|
||||||
impl<F, O> HttpAuthentication<basic::BasicAuth, F>
|
impl<F, O> HttpAuthentication<basic::BasicAuth, F>
|
||||||
where
|
where
|
||||||
F: FnMut(ServiceRequest, basic::BasicAuth) -> O,
|
F: Fn(ServiceRequest, basic::BasicAuth) -> O,
|
||||||
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
||||||
{
|
{
|
||||||
/// Construct `HttpAuthentication` middleware for the HTTP "Basic"
|
/// Construct `HttpAuthentication` middleware for the HTTP "Basic"
|
||||||
@ -86,7 +86,7 @@ where
|
|||||||
|
|
||||||
impl<F, O> HttpAuthentication<bearer::BearerAuth, F>
|
impl<F, O> HttpAuthentication<bearer::BearerAuth, F>
|
||||||
where
|
where
|
||||||
F: FnMut(ServiceRequest, bearer::BearerAuth) -> O,
|
F: Fn(ServiceRequest, bearer::BearerAuth) -> O,
|
||||||
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
O: IntoFuture<Item = ServiceRequest, Error = Error>,
|
||||||
{
|
{
|
||||||
/// Construct `HttpAuthentication` middleware for the HTTP "Bearer"
|
/// Construct `HttpAuthentication` middleware for the HTTP "Bearer"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user