From 2ce3e5fb784ca4c7e71caa8f973884726517f0c7 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 29 Sep 2021 09:04:17 +0200 Subject: [PATCH] rest-server: use hypers AddrIncoming for proxmox-backup-api this has a 'from_listener' (tokio::net::TcpListener) since hyper 0.14.5 in the 'tcp' feature (we use 'full', which includes that; since 0.14.13 it is not behind a feature flag anymore). this makes it possible to create a hyper server without our 'StaticIncoming' wrapper and thus makes it unnecessary. The only other thing we have to do is to change the Service impl from tokio::net::TcpStream to hyper::server::conn::AddStream to fulfill the trait requirements. Signed-off-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- proxmox-rest-server/Cargo.toml | 2 +- proxmox-rest-server/src/rest.rs | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/proxmox-rest-server/Cargo.toml b/proxmox-rest-server/Cargo.toml index b0e53d19..9a305364 100644 --- a/proxmox-rest-server/Cargo.toml +++ b/proxmox-rest-server/Cargo.toml @@ -10,7 +10,7 @@ anyhow = "1.0" futures = "0.3" handlebars = "3.0" http = "0.2" -hyper = { version = "0.14", features = [ "full" ] } +hyper = { version = "0.14.5", features = [ "full" ] } lazy_static = "1.4" libc = "0.2" log = "0.4" diff --git a/proxmox-rest-server/src/rest.rs b/proxmox-rest-server/src/rest.rs index ba2edf11..8c1e34a3 100644 --- a/proxmox-rest-server/src/rest.rs +++ b/proxmox-rest-server/src/rest.rs @@ -93,7 +93,7 @@ impl tower_service::Service<&Pin for RestServer { +impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer { type Response = ApiService; type Error = Error; type Future = Pin> + Send>>; @@ -102,15 +102,13 @@ impl tower_service::Service<&tokio::net::TcpStream> for RestServer { Poll::Ready(Ok(())) } - fn call(&mut self, ctx: &tokio::net::TcpStream) -> Self::Future { - match ctx.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(), - } + fn call(&mut self, ctx: &hyper::server::conn::AddrStream) -> Self::Future { + let peer = ctx.remote_addr(); + future::ok(ApiService { + peer, + api_config: self.api_config.clone(), + }) + .boxed() } }