[pbs-devel] [PATCH proxmox-backup 4/6] restore daemon: adapt to hyper/http 1.0

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Mar 26 16:23:25 CET 2025


like pbs-client and proxmox-http.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
 proxmox-restore-daemon/Cargo.toml             |  2 ++
 proxmox-restore-daemon/src/main.rs            | 24 ++++++++++++++-----
 .../src/proxmox_restore_daemon/api.rs         |  6 +++--
 .../src/proxmox_restore_daemon/auth.rs        |  5 ++--
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml
index bcb50d8ba..4a48518ab 100644
--- a/proxmox-restore-daemon/Cargo.toml
+++ b/proxmox-restore-daemon/Cargo.toml
@@ -12,6 +12,7 @@ base64.workspace = true
 env_logger.workspace = true
 futures.workspace = true
 hyper.workspace = true
+hyper-util = { workspace = true, features = [ "service" ] }
 libc.workspace = true
 log.workspace = true
 nix.workspace = true
@@ -26,6 +27,7 @@ pxar.workspace = true
 
 proxmox-async.workspace = true
 proxmox-compression.workspace = true
+proxmox-http.workspace = true
 proxmox-rest-server.workspace = true
 proxmox-router = { workspace = true, features = [ "cli", "server" ] }
 proxmox-schema = { workspace = true, features = [ "api-macro" ] }
diff --git a/proxmox-restore-daemon/src/main.rs b/proxmox-restore-daemon/src/main.rs
index 7f61faed8..74ba1cd8d 100644
--- a/proxmox-restore-daemon/src/main.rs
+++ b/proxmox-restore-daemon/src/main.rs
@@ -9,6 +9,9 @@ use std::path::Path;
 use std::sync::{Arc, LazyLock, Mutex};
 
 use anyhow::{bail, format_err, Error};
+use futures::StreamExt;
+use hyper_util::rt::TokioIo;
+use hyper_util::service::TowerToHyperService;
 use log::{error, info};
 use tokio::sync::mpsc;
 use tokio_stream::wrappers::ReceiverStream;
@@ -114,14 +117,23 @@ async fn run() -> Result<(), Error> {
 
     let vsock_fd = get_vsock_fd()?;
     let connections = accept_vsock_connections(vsock_fd);
-    let receiver_stream = ReceiverStream::new(connections);
-    let acceptor = hyper::server::accept::from_stream(receiver_stream);
+    let mut receiver_stream = ReceiverStream::new(connections);
 
     let hyper_future = async move {
-        hyper::Server::builder(acceptor)
-            .serve(rest_server)
-            .await
-            .map_err(|err| format_err!("hyper finished with error: {}", err))
+        while let Some(conn) = receiver_stream.next().await {
+            let conn = conn?;
+
+            let api_service = TowerToHyperService::new(rest_server.api_service(&conn)?);
+
+            let conn = hyper::server::conn::http1::Builder::new()
+                .serve_connection(TokioIo::new(conn), api_service);
+
+            tokio::spawn(async move {
+                conn.await
+                    .map_err(|err| format_err!("hyper finished with error: {}", err))
+            });
+        }
+        Ok(())
     };
 
     tokio::try_join!(init_future, hyper_future)?;
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
index 8955772bc..0d8569402 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/api.rs
@@ -6,14 +6,16 @@ use std::path::{Path, PathBuf};
 
 use anyhow::{bail, Error};
 use futures::FutureExt;
+use hyper::body::Incoming;
 use hyper::http::request::Parts;
-use hyper::{header, Body, Response, StatusCode};
+use hyper::{header, Response, StatusCode};
 use log::error;
 use serde_json::Value;
 use tokio::sync::Semaphore;
 
 use pathpatterns::{MatchEntry, MatchPattern, MatchType, Pattern};
 use proxmox_compression::{tar::tar_directory, zip::zip_directory, zstd::ZstdEncoder};
+use proxmox_http::Body;
 use proxmox_router::{
     list_subdirs_api_method, ApiHandler, ApiMethod, ApiResponseFuture, Permission, Router,
     RpcEnvironment, SubdirMap,
@@ -264,7 +266,7 @@ pub const API_METHOD_EXTRACT: ApiMethod = ApiMethod::new(
 
 fn extract(
     _parts: Parts,
-    _req_body: Body,
+    _req_body: Incoming,
     param: Value,
     _info: &ApiMethod,
     _rpcenv: Box<dyn RpcEnvironment>,
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
index 8173d48a0..e346aebd3 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
@@ -7,8 +7,9 @@ use std::sync::Arc;
 
 use anyhow::{bail, format_err, Error};
 use hyper::http::HeaderMap;
-use hyper::{Body, Method, Response, StatusCode};
+use hyper::{Method, Response, StatusCode};
 
+use proxmox_http::Body;
 use proxmox_router::UserInformation;
 
 use proxmox_rest_server::AuthError;
@@ -69,7 +70,7 @@ pub fn get_index() -> Pin<Box<dyn Future<Output = hyper::http::Response<Body>> +
         Response::builder()
             .status(StatusCode::OK)
             .header(hyper::header::CONTENT_TYPE, "text/html")
-            .body(index.into())
+            .body(index.to_owned().into())
             .unwrap()
     })
 }
-- 
2.39.5





More information about the pbs-devel mailing list