From 10a3ab222b04b0e7cb7bb6eaaa2c2a4b18799f6a Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 25 Jan 2023 11:43:01 +0100 Subject: [PATCH] http: move rate-limiting out of client feature this can now be used separately Signed-off-by: Wolfgang Bumiller --- proxmox-http/Cargo.toml | 2 ++ proxmox-http/src/client/connector.rs | 2 +- proxmox-http/src/client/mod.rs | 10 ---------- proxmox-http/src/lib.rs | 10 ++++++++++ proxmox-http/src/{client => }/rate_limited_stream.rs | 2 +- proxmox-http/src/{client => }/rate_limiter.rs | 0 6 files changed, 14 insertions(+), 12 deletions(-) rename proxmox-http/src/{client => }/rate_limited_stream.rs (99%) rename proxmox-http/src/{client => }/rate_limiter.rs (100%) diff --git a/proxmox-http/Cargo.toml b/proxmox-http/Cargo.toml index 4c3251d4..f87ed2f2 100644 --- a/proxmox-http/Cargo.toml +++ b/proxmox-http/Cargo.toml @@ -30,6 +30,8 @@ proxmox-lang = { workspace = true, optional = true } [features] default = [] +rate-limiter = ["dep:hyper"] +rate-limited-stream = ["rate-limiter", "dep:tokio", "dep:hyper", "hyper?/client", "tokio?/time", "tokio?/net"] client = [ "dep:futures", "http-helpers", "dep:hyper", "hyper?/full", "dep:openssl", "dep:tokio", "tokio?/io-util", "dep:tokio-openssl" ] client-sync = [ "client-trait", "http-helpers", "dep:ureq" ] client-trait = [ "dep:http" ] diff --git a/proxmox-http/src/client/connector.rs b/proxmox-http/src/client/connector.rs index f3e7535a..63b9d10c 100644 --- a/proxmox-http/src/client/connector.rs +++ b/proxmox-http/src/client/connector.rs @@ -18,7 +18,7 @@ use crate::proxy_config::ProxyConfig; use crate::uri::build_authority; use super::tls::MaybeTlsStream; -use super::{RateLimitedStream, ShareableRateLimit}; +use crate::{RateLimitedStream, ShareableRateLimit}; type SharedRateLimit = Arc; diff --git a/proxmox-http/src/client/mod.rs b/proxmox-http/src/client/mod.rs index 86d94dcd..2b638605 100644 --- a/proxmox-http/src/client/mod.rs +++ b/proxmox-http/src/client/mod.rs @@ -8,16 +8,6 @@ //! //! Both clients implement [`HttpClient`](crate::HttpClient) if the feature `client-trait` is enabled. -#[cfg(feature = "client")] -mod rate_limiter; -#[cfg(feature = "client")] -pub use rate_limiter::{RateLimit, RateLimiter, RateLimiterVec, ShareableRateLimit}; - -#[cfg(feature = "client")] -mod rate_limited_stream; -#[cfg(feature = "client")] -pub use rate_limited_stream::RateLimitedStream; - #[cfg(feature = "client")] mod connector; #[cfg(feature = "client")] diff --git a/proxmox-http/src/lib.rs b/proxmox-http/src/lib.rs index 40efcd1d..640bd574 100644 --- a/proxmox-http/src/lib.rs +++ b/proxmox-http/src/lib.rs @@ -23,3 +23,13 @@ pub mod client; mod client_trait; #[cfg(feature = "client-trait")] pub use client_trait::HttpClient; + +#[cfg(feature = "rate-limiter")] +mod rate_limiter; +#[cfg(feature = "rate-limiter")] +pub use rate_limiter::{RateLimit, RateLimiter, RateLimiterVec, ShareableRateLimit}; + +#[cfg(feature = "rate-limited-stream")] +mod rate_limited_stream; +#[cfg(feature = "rate-limited-stream")] +pub use rate_limited_stream::RateLimitedStream; diff --git a/proxmox-http/src/client/rate_limited_stream.rs b/proxmox-http/src/rate_limited_stream.rs similarity index 99% rename from proxmox-http/src/client/rate_limited_stream.rs rename to proxmox-http/src/rate_limited_stream.rs index 0fbc559a..c3756ddf 100644 --- a/proxmox-http/src/client/rate_limited_stream.rs +++ b/proxmox-http/src/rate_limited_stream.rs @@ -1,10 +1,10 @@ +use std::future::Future; use std::io::IoSlice; use std::marker::Unpin; use std::pin::Pin; use std::sync::{Arc, Mutex}; use std::time::{Duration, Instant}; -use futures::Future; use hyper::client::connect::{Connected, Connection}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio::time::Sleep; diff --git a/proxmox-http/src/client/rate_limiter.rs b/proxmox-http/src/rate_limiter.rs similarity index 100% rename from proxmox-http/src/client/rate_limiter.rs rename to proxmox-http/src/rate_limiter.rs