From 4b3e0e331c7455d59ddf289f60343ef279348bb2 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 4 Nov 2021 13:42:30 +0100 Subject: [PATCH] implement Servive for RateLimitedStream Signed-off-by: Dietmar Maurer --- proxmox-rest-server/Cargo.toml | 1 + proxmox-rest-server/src/rest.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml index 1fa76f21..b88e5d12 100644 --- a/proxmox-rest-server/Cargo.toml +++ b/proxmox-rest-server/Cargo.toml @@ -33,6 +33,7 @@ url = "2.1" proxmox = "0.15.0" proxmox-io = "1" proxmox-lang = "1" +proxmox-http = { version = "0.5.0", features = [ "client" ] } proxmox-router = "1.1" proxmox-schema = { version = "1", features = [ "api-macro", "upid-api-impl" ] } proxmox-time = "1" diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index 74bc8bb1..f27f703d 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -31,6 +31,8 @@ use proxmox_schema::{ ParameterSchema, }; +use proxmox_http::client::RateLimitedStream; + use pbs_tools::compression::{DeflateEncoder, Level}; use pbs_tools::stream::AsyncReaderStream; @@ -73,6 +75,32 @@ impl RestServer { } } +impl Service<&Pin>>>> + for RestServer +{ + type Response = ApiService; + type Error = Error; + type Future = Pin> + Send>>; + + fn poll_ready(&mut self, _cx: &mut Context) -> Poll> { + Poll::Ready(Ok(())) + } + + fn call( + &mut self, + ctx: &Pin>>>, + ) -> Self::Future { + match ctx.get_ref().peer_addr() { + Err(err) => future::err(format_err!("unable to get peer address - {}", err)).boxed(), + Ok(peer) => future::ok(ApiService { + peer, + api_config: self.api_config.clone(), + }) + .boxed(), + } + } +} + impl Service<&Pin>>> for RestServer {