From 385e1e53c1b91fa32f3b01a603072ee9be39fbbe Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Wed, 19 Jul 2023 02:41:40 -0400 Subject: [PATCH] update middleware --- Cargo.lock | 2 ++ .../banned_cidr_filter/banned_cidr_filter.rs | 6 ++--- .../banned_cidr_filter_middleware.rs | 18 +++++++------ .../banned_ip_filter/banned_ip_filter.rs | 6 ++--- .../banned_ip_filter_middleware.rs | 18 +++++++------ .../disabled_endpoint_filter.rs | 6 ++--- .../disabled_endpoint_filter_middleware.rs | 18 +++++++------ crates/service/web/storyteller_web/Cargo.toml | 2 ++ .../middleware/pushback_filter_middleware.rs | 27 ++++++++++++------- 9 files changed, 60 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2c3254c2c3..4a318fa91f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6563,6 +6563,7 @@ dependencies = [ "errors", "futures 0.1.31", "futures 0.3.26", + "futures-core", "futures-util", "google_drive_common", "hashing", @@ -6590,6 +6591,7 @@ dependencies = [ "native-tls", "newrelic-telemetry", "once_cell", + "pin-project-lite 0.2.9", "pulldown-cmark", "r2d2_redis", "rand 0.8.5", diff --git a/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter.rs b/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter.rs index 32e446be95..0241074928 100644 --- a/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter.rs +++ b/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter.rs @@ -23,12 +23,12 @@ impl BannedCidrFilter { } } -impl Transform for BannedCidrFilter +impl Transform for BannedCidrFilter where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type InitError = (); type Transform = BannedCidrFilterMiddleware; diff --git a/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter_middleware.rs b/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter_middleware.rs index a54925285d..b7086c8f6a 100644 --- a/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter_middleware.rs +++ b/crates/lib/actix_helpers/src/middleware/banned_cidr_filter/banned_cidr_filter_middleware.rs @@ -7,26 +7,28 @@ use crate::middleware::banned_ip_filter::banned_error::BannedError; use futures_util::future::{err, Either, Ready}; use std::net::IpAddr; use std::str::FromStr; -use std::task::{Context, Poll}; +//use std::task::{Context, Poll}; pub struct BannedCidrFilterMiddleware { pub (crate) service: S, pub (crate) cidr_bans: BannedCidrSet, } -impl Service for BannedCidrFilterMiddleware +impl Service for BannedCidrFilterMiddleware where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type Future = Either>>; - // alternatively(?), actix_service::forward_ready!(service); - fn poll_ready(&self, cx: &mut Context) -> Poll> { - self.service.poll_ready(cx) - } + //// alternatively(?), actix_service::forward_ready!(service); + //fn poll_ready(&self, cx: &mut Context) -> Poll> { + // self.service.poll_ready(cx) + //} + + actix_service::forward_ready!(service); fn call(&self, request: ServiceRequest) -> Self::Future { let ip_address = get_service_request_ip_address(&request); diff --git a/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter.rs b/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter.rs index 55fb4a3fd9..e06f8f32bb 100644 --- a/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter.rs +++ b/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter.rs @@ -23,12 +23,12 @@ impl BannedIpFilter { } } -impl Transform for BannedIpFilter +impl Transform for BannedIpFilter where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type InitError = (); type Transform = BannedIpFilterMiddleware; diff --git a/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter_middleware.rs b/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter_middleware.rs index abc46dd91d..1c5d0e8658 100644 --- a/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter_middleware.rs +++ b/crates/lib/actix_helpers/src/middleware/banned_ip_filter/banned_ip_filter_middleware.rs @@ -5,7 +5,7 @@ use crate::extractors::get_service_request_ip_address::get_service_request_ip_ad use crate::middleware::banned_ip_filter::banned_error::BannedError; use crate::middleware::banned_ip_filter::ip_ban_list::ip_ban_list::IpBanList; use futures_util::future::{err, Either, Ready}; -use std::task::{Context, Poll}; +//use std::task::{Context, Poll}; // There are two steps in middleware processing. // 1. Middleware initialization, middleware factory gets called with @@ -17,19 +17,21 @@ pub struct BannedIpFilterMiddleware { pub (crate) ip_ban_list: IpBanList, } -impl Service for BannedIpFilterMiddleware +impl Service for BannedIpFilterMiddleware where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type Future = Either>>; - // alternatively(?), actix_service::forward_ready!(service); - fn poll_ready(&self, cx: &mut Context) -> Poll> { - self.service.poll_ready(cx) - } + //// alternatively(?), actix_service::forward_ready!(service); + //fn poll_ready(&self, cx: &mut Context) -> Poll> { + // self.service.poll_ready(cx) + //} + + actix_service::forward_ready!(service); fn call(&self, request: ServiceRequest) -> Self::Future { let ip_address = get_service_request_ip_address(&request); diff --git a/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter.rs b/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter.rs index 4cef0b121c..4a314a6d31 100644 --- a/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter.rs +++ b/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter.rs @@ -23,12 +23,12 @@ impl DisabledEndpointFilter { } } -impl Transform for DisabledEndpointFilter +impl Transform for DisabledEndpointFilter where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type InitError = (); type Transform = DisabledEndpointFilterMiddleware; diff --git a/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter_middleware.rs b/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter_middleware.rs index 703c344e97..cf43ada21f 100644 --- a/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter_middleware.rs +++ b/crates/lib/actix_helpers/src/middleware/disabled_endpoint_filter/disabled_endpoint_filter_middleware.rs @@ -4,7 +4,7 @@ use actix_web::dev::{ServiceRequest, ServiceResponse}; use crate::middleware::disabled_endpoint_filter::disabled_endpoints::disabled_endpoints::DisabledEndpoints; use crate::middleware::disabled_endpoint_filter::disabled_error::DisabledError; use futures_util::future::{err, Either, Ready}; -use std::task::{Context, Poll}; +//use std::task::{Context, Poll}; // There are two steps in middleware processing. // 1. Middleware initialization, middleware factory gets called with @@ -16,19 +16,21 @@ pub struct DisabledEndpointFilterMiddleware { pub (crate) disabled_endpoints: DisabledEndpoints, } -impl Service for DisabledEndpointFilterMiddleware +impl Service for DisabledEndpointFilterMiddleware where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type Future = Either>>; - // alternatively(?), actix_service::forward_ready!(service); - fn poll_ready(&self, cx: &mut Context) -> Poll> { - self.service.poll_ready(cx) - } + //// alternatively(?), actix_service::forward_ready!(service); + //fn poll_ready(&self, cx: &mut Context) -> Poll> { + // self.service.poll_ready(cx) + //} + + actix_service::forward_ready!(service); fn call(&self, request: ServiceRequest) -> Self::Future { let endpoint = request.path(); diff --git a/crates/service/web/storyteller_web/Cargo.toml b/crates/service/web/storyteller_web/Cargo.toml index fabf0eee27..549956f1ad 100644 --- a/crates/service/web/storyteller_web/Cargo.toml +++ b/crates/service/web/storyteller_web/Cargo.toml @@ -96,6 +96,8 @@ tokio = { version = "1.6.0", features = ["macros"] } futures = { version = "0.3.17", features = ["thread-pool"] } # feature for ThreadPool futures-util = "0.3.9" futures_old_for_limiter = { package = "futures", version = "0.1.29" } # Older version of futures for `limiter` crate +futures-core = "0.3.26" # NB: For middleware/futures upgrade +pin-project-lite = "0.2.9" # NB: For middleware/futures upgrade # MySql Database # "offline" supports typesafe builds without a live database diff --git a/crates/service/web/storyteller_web/src/http_server/middleware/pushback_filter_middleware.rs b/crates/service/web/storyteller_web/src/http_server/middleware/pushback_filter_middleware.rs index c69c3a3900..f73d6d84f9 100644 --- a/crates/service/web/storyteller_web/src/http_server/middleware/pushback_filter_middleware.rs +++ b/crates/service/web/storyteller_web/src/http_server/middleware/pushback_filter_middleware.rs @@ -11,10 +11,15 @@ use actix_web::{ResponseError, HttpMessage, HttpRequest, HttpResponseBuilder}; use crate::http_server::web_utils::response_error_helpers::to_simple_json_error; use crate::server_state::StaticFeatureFlags; use errors::AnyhowResult; +use futures_core::ready; use futures_util::future::{err, ok, Either, Ready}; use http_server_common::request::get_request_ip::get_service_request_ip; use log::warn; +use pin_project_lite::pin_project; +use std::future::Future; use std::io::Write; +use std::marker::PhantomData; +use std::pin::Pin; use std::task::{Context, Poll}; // There are two steps in middleware processing. @@ -62,12 +67,12 @@ impl PushbackFilter { } } -impl Transform for PushbackFilter +impl Transform for PushbackFilter where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type InitError = (); type Transform = PushbackFilterMiddleware; @@ -83,19 +88,21 @@ pub struct PushbackFilterMiddleware { feature_flags: StaticFeatureFlags, } -impl Service for PushbackFilterMiddleware +impl Service for PushbackFilterMiddleware where - S: Service, + S: Service, Error = Error>, S::Future: 'static, { - type Response = ServiceResponse; + type Response = ServiceResponse; type Error = Error; type Future = Either>>; - // alternatively(?), actix_service::forward_ready!(service); - fn poll_ready(&self, cx: &mut Context) -> Poll> { - self.service.poll_ready(cx) - } + //// alternatively(?), actix_service::forward_ready!(service); + //fn poll_ready(&self, cx: &mut Context) -> Poll> { + // self.service.poll_ready(cx) + //} + + actix_service::forward_ready!(service); fn call(&self, req: ServiceRequest) -> Self::Future { // NB: Ordinarily the filter should be disabled.