From 10fe10c9c1419882a2df80b14bf677164449917e Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 21 May 2020 17:23:59 +0900 Subject: [PATCH] httpauth: Minimize `futures` dependency --- actix-web-httpauth/CHANGES.md | 1 + actix-web-httpauth/Cargo.toml | 2 +- actix-web-httpauth/src/extractors/basic.rs | 10 +++++----- actix-web-httpauth/src/extractors/bearer.rs | 10 +++++----- actix-web-httpauth/src/extractors/mod.rs | 2 +- actix-web-httpauth/src/middleware.rs | 9 +++++---- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/actix-web-httpauth/CHANGES.md b/actix-web-httpauth/CHANGES.md index bdc639fdf..9ff0a025c 100644 --- a/actix-web-httpauth/CHANGES.md +++ b/actix-web-httpauth/CHANGES.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] - Update the `base64` dependency to 0.12 - AuthenticationError's status code is preserved when converting to a ResponseError + - Minimize `futures` dependency ## [0.4.1] - 2020-02-19 - Move repository to actix-extras diff --git a/actix-web-httpauth/Cargo.toml b/actix-web-httpauth/Cargo.toml index 67c2119b6..46e30d32a 100644 --- a/actix-web-httpauth/Cargo.toml +++ b/actix-web-httpauth/Cargo.toml @@ -19,7 +19,7 @@ path = "src/lib.rs" [dependencies] actix-web = { version = "^2.0", default_features = false } actix-service = "1.0" -futures = "0.3" +futures-util = { version = "0.3", default-features = false } bytes = "0.5" base64 = "0.12" diff --git a/actix-web-httpauth/src/extractors/basic.rs b/actix-web-httpauth/src/extractors/basic.rs index 467be7f02..ef262b45d 100644 --- a/actix-web-httpauth/src/extractors/basic.rs +++ b/actix-web-httpauth/src/extractors/basic.rs @@ -5,7 +5,7 @@ use std::borrow::Cow; use actix_web::dev::{Payload, ServiceRequest}; use actix_web::http::header::Header; use actix_web::{FromRequest, HttpRequest}; -use futures::future; +use futures_util::future::{ready, Ready}; use super::config::AuthExtractorConfig; use super::errors::AuthenticationError; @@ -104,7 +104,7 @@ impl BasicAuth { } impl FromRequest for BasicAuth { - type Future = future::Ready>; + type Future = Ready>; type Config = Config; type Error = AuthenticationError; @@ -112,7 +112,7 @@ impl FromRequest for BasicAuth { req: &HttpRequest, _: &mut Payload, ) -> ::Future { - future::ready( + ready( Authorization::::parse(req) .map(|auth| BasicAuth(auth.into_scheme())) .map_err(|_| { @@ -131,10 +131,10 @@ impl FromRequest for BasicAuth { impl AuthExtractor for BasicAuth { type Error = AuthenticationError; - type Future = future::Ready>; + type Future = Ready>; fn from_service_request(req: &ServiceRequest) -> Self::Future { - future::ready( + ready( Authorization::::parse(req) .map(|auth| BasicAuth(auth.into_scheme())) .map_err(|_| { diff --git a/actix-web-httpauth/src/extractors/bearer.rs b/actix-web-httpauth/src/extractors/bearer.rs index 566e77b8d..f73c22d11 100644 --- a/actix-web-httpauth/src/extractors/bearer.rs +++ b/actix-web-httpauth/src/extractors/bearer.rs @@ -6,7 +6,7 @@ use std::default::Default; use actix_web::dev::{Payload, ServiceRequest}; use actix_web::http::header::Header; use actix_web::{FromRequest, HttpRequest}; -use futures::future; +use futures_util::future::{ready, Ready}; use super::config::AuthExtractorConfig; use super::errors::AuthenticationError; @@ -104,14 +104,14 @@ impl BearerAuth { impl FromRequest for BearerAuth { type Config = Config; - type Future = future::Ready>; + type Future = Ready>; type Error = AuthenticationError; fn from_request( req: &HttpRequest, _payload: &mut Payload, ) -> ::Future { - future::ready( + ready( authorization::Authorization::::parse(req) .map(|auth| BearerAuth(auth.into_scheme())) .map_err(|_| { @@ -127,11 +127,11 @@ impl FromRequest for BearerAuth { } impl AuthExtractor for BearerAuth { - type Future = future::Ready>; + type Future = Ready>; type Error = AuthenticationError; fn from_service_request(req: &ServiceRequest) -> Self::Future { - future::ready( + ready( authorization::Authorization::::parse(req) .map(|auth| BearerAuth(auth.into_scheme())) .map_err(|_| { diff --git a/actix-web-httpauth/src/extractors/mod.rs b/actix-web-httpauth/src/extractors/mod.rs index 27a3e4e33..1fe9b7d9a 100644 --- a/actix-web-httpauth/src/extractors/mod.rs +++ b/actix-web-httpauth/src/extractors/mod.rs @@ -2,7 +2,7 @@ use actix_web::dev::ServiceRequest; use actix_web::Error; -use futures::future::Future; +use std::future::Future; pub mod basic; pub mod bearer; diff --git a/actix-web-httpauth/src/middleware.rs b/actix-web-httpauth/src/middleware.rs index f0ce7fc28..15eb25885 100644 --- a/actix-web-httpauth/src/middleware.rs +++ b/actix-web-httpauth/src/middleware.rs @@ -1,5 +1,6 @@ //! HTTP Authentication middleware. +use std::future::Future; use std::marker::PhantomData; use std::pin::Pin; use std::sync::Arc; @@ -7,9 +8,9 @@ use std::sync::Arc; use actix_service::{Service, Transform}; use actix_web::dev::{ServiceRequest, ServiceResponse}; use actix_web::Error; -use futures::future::{self, Future, FutureExt, LocalBoxFuture, TryFutureExt}; -use futures::lock::Mutex; -use futures::task::{Context, Poll}; +use futures_util::future::{self, FutureExt, LocalBoxFuture, TryFutureExt}; +use futures_util::lock::Mutex; +use futures_util::task::{Context, Poll}; use crate::extractors::{basic, bearer, AuthExtractor}; @@ -239,7 +240,7 @@ where .f .as_mut() .expect("Extraction future should be initialized at this point"); - let credentials = futures::ready!(Future::poll(f.as_mut(), ctx))?; + let credentials = futures_util::ready!(Future::poll(f.as_mut(), ctx))?; let req = self.req.take().expect("Extract future was polled twice!"); Poll::Ready(Ok((req, credentials)))