From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 405347D4C4 for ; Tue, 9 Nov 2021 07:53:03 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3EA792DF99 for ; Tue, 9 Nov 2021 07:53:03 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7F60B2DF63 for ; Tue, 9 Nov 2021 07:53:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3FDFB45E4D; Tue, 9 Nov 2021 07:52:56 +0100 (CET) From: Dietmar Maurer To: pbs-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 07:52:43 +0100 Message-Id: <20211109065253.980304-7-dietmar@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109065253.980304-1-dietmar@proxmox.com> References: <20211109065253.980304-1-dietmar@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.517 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [rest.rs] Subject: [pbs-devel] [PATCH proxmox-backup 3/9] implement Servive for RateLimitedStream X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 06:53:03 -0000 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 { -- 2.30.2