]> git.proxmox.com Git - proxmox-backup.git/commitdiff
rest-server: use hypers AddrIncoming for proxmox-backup-api
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 29 Sep 2021 07:04:17 +0000 (09:04 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 29 Sep 2021 07:38:40 +0000 (09:38 +0200)
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 <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-rest-server/Cargo.toml
proxmox-rest-server/src/rest.rs
src/bin/proxmox-backup-api.rs

index b0e53d192194fde1e2539f7335eb907735860207..9a305364f76a2610f37229efec4a7357b4bbe6f4 100644 (file)
@@ -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"
index ba2edf116bbbf36142b84c781599e0f1b3d43c2c..8c1e34a3d52596f65266943f0885226372ecef16 100644 (file)
@@ -93,7 +93,7 @@ impl tower_service::Service<&Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStr
     }
 }
 
-impl tower_service::Service<&tokio::net::TcpStream> for RestServer {
+impl tower_service::Service<&hyper::server::conn::AddrStream> for RestServer {
     type Response = ApiService;
     type Error = Error;
     type Future = Pin<Box<dyn Future<Output = Result<ApiService, Error>> + 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()
     }
 }
 
index 86650de6227b8f807c6ad55423aec42fd96650c8..e3f2531f8b950b9cadebcd7e92350f48dad6b830 100644 (file)
@@ -108,7 +108,8 @@ async fn run() -> Result<(), Error> {
     let server = daemon::create_daemon(
         ([127,0,0,1], 82).into(),
         move |listener, ready| {
-            let incoming = proxmox_backup::tools::async_io::StaticIncoming::from(listener);
+            let incoming = hyper::server::conn::AddrIncoming::from_listener(listener)?;
+
             Ok(ready
                 .and_then(|_| hyper::Server::builder(incoming)
                     .serve(rest_server)