[pbs-devel] [PATCH proxmox-backup] cargo: drop direct `http` crate dependency, tree-wide namespace fix

Christian Ebner c.ebner at proxmox.com
Tue Jan 21 13:33:19 CET 2025


Instead of using and depending on the `http` create directly, use and
depend on the re-exported `hyper::http`. Adapt namespace prefixes
accordingly.

This makes sure the `hyper::http` types are version compatible and
allows to possibly depend on incompatible versions of `http` in the
workspace in the future.

No functional changes intended.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 Cargo.toml                                                | 2 --
 examples/h2client.rs                                      | 2 +-
 examples/h2s-client.rs                                    | 2 +-
 examples/h2s-server.rs                                    | 4 ++--
 examples/h2server.rs                                      | 4 ++--
 pbs-client/Cargo.toml                                     | 1 -
 pbs-client/src/http_client.rs                             | 8 ++++----
 pbs-client/src/vsock_client.rs                            | 4 ++--
 proxmox-restore-daemon/Cargo.toml                         | 1 -
 proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs | 4 ++--
 src/acme/plugin.rs                                        | 4 ++--
 src/api2/backup/mod.rs                                    | 2 +-
 src/api2/node/tasks.rs                                    | 4 ++--
 src/api2/reader/mod.rs                                    | 2 +-
 src/bin/proxmox-backup-api.rs                             | 2 +-
 src/bin/proxmox-backup-proxy.rs                           | 8 ++++----
 src/server/auth.rs                                        | 2 +-
 src/server/sync.rs                                        | 2 +-
 18 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index adeeb6efa..ab066fff0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -128,7 +128,6 @@ futures = "0.3"
 h2 = { version = "0.4", features = [ "stream" ] }
 handlebars = "3.0"
 hex = "0.4.3"
-http = "0.2"
 hyper = { version = "0.14", features = [ "full" ] }
 libc = "0.2"
 log = "0.4.17"
@@ -175,7 +174,6 @@ endian_trait.workspace = true
 futures.workspace = true
 h2.workspace = true
 hex.workspace = true
-http.workspace = true
 hyper.workspace = true
 libc.workspace = true
 log.workspace = true
diff --git a/examples/h2client.rs b/examples/h2client.rs
index 2588631e4..1dcb44987 100644
--- a/examples/h2client.rs
+++ b/examples/h2client.rs
@@ -54,7 +54,7 @@ fn send_request(
 ) -> impl Future<Output = Result<usize, Error>> {
     println!("sending request");
 
-    let request = http::Request::builder()
+    let request = hyper::http::Request::builder()
         .uri("http://localhost/")
         .body(())
         .unwrap();
diff --git a/examples/h2s-client.rs b/examples/h2s-client.rs
index 356dbc592..a12b5a484 100644
--- a/examples/h2s-client.rs
+++ b/examples/h2s-client.rs
@@ -54,7 +54,7 @@ fn send_request(
 ) -> impl Future<Output = Result<usize, Error>> {
     println!("sending request");
 
-    let request = http::Request::builder()
+    let request = hyper::http::Request::builder()
         .uri("http://localhost/")
         .body(())
         .unwrap();
diff --git a/examples/h2s-server.rs b/examples/h2s-server.rs
index f1f085137..52c4568a5 100644
--- a/examples/h2s-server.rs
+++ b/examples/h2s-server.rs
@@ -63,8 +63,8 @@ async fn handle_connection(socket: TcpStream, acceptor: Arc<SslAcceptor>) -> Res
         let body = Body::from(buffer);
 
         let response = Response::builder()
-            .status(http::StatusCode::OK)
-            .header(http::header::CONTENT_TYPE, "application/octet-stream")
+            .status(hyper::http::StatusCode::OK)
+            .header(hyper::http::header::CONTENT_TYPE, "application/octet-stream")
             .body(body)
             .unwrap();
         future::ok::<_, Error>(response)
diff --git a/examples/h2server.rs b/examples/h2server.rs
index 5802fc888..2d2715f13 100644
--- a/examples/h2server.rs
+++ b/examples/h2server.rs
@@ -39,8 +39,8 @@ async fn handle_connection(socket: TcpStream) -> Result<(), Error> {
         let body = Body::from(buffer);
 
         let response = Response::builder()
-            .status(http::StatusCode::OK)
-            .header(http::header::CONTENT_TYPE, "application/octet-stream")
+            .status(hyper::http::StatusCode::OK)
+            .header(hyper::http::header::CONTENT_TYPE, "application/octet-stream")
             .body(body)
             .unwrap();
         future::ok::<_, Error>(response)
diff --git a/pbs-client/Cargo.toml b/pbs-client/Cargo.toml
index 212f62f2a..c28fe87ca 100644
--- a/pbs-client/Cargo.toml
+++ b/pbs-client/Cargo.toml
@@ -12,7 +12,6 @@ bytes.workspace = true
 futures.workspace = true
 h2.workspace = true
 hex.workspace = true
-http.workspace = true
 hyper.workspace = true
 libc.workspace = true
 nix.workspace = true
diff --git a/pbs-client/src/http_client.rs b/pbs-client/src/http_client.rs
index e97b4e549..48cb776dc 100644
--- a/pbs-client/src/http_client.rs
+++ b/pbs-client/src/http_client.rs
@@ -4,9 +4,9 @@ use std::time::Duration;
 
 use anyhow::{bail, format_err, Error};
 use futures::*;
-use http::header::HeaderValue;
-use http::Uri;
-use http::{Request, Response};
+use hyper::http::header::HeaderValue;
+use hyper::http::Uri;
+use hyper::http::{Request, Response};
 use hyper::client::{Client, HttpConnector};
 use hyper::Body;
 use openssl::{
@@ -782,7 +782,7 @@ impl HttpClient {
             .map_err(|_| format_err!("http upgrade request timed out"))??;
         let status = resp.status();
 
-        if status != http::StatusCode::SWITCHING_PROTOCOLS {
+        if status != hyper::http::StatusCode::SWITCHING_PROTOCOLS {
             Self::api_response(resp).await?;
             bail!("unknown error");
         }
diff --git a/pbs-client/src/vsock_client.rs b/pbs-client/src/vsock_client.rs
index 6d62cd93f..25aa69cb9 100644
--- a/pbs-client/src/vsock_client.rs
+++ b/pbs-client/src/vsock_client.rs
@@ -3,8 +3,8 @@ use std::task::{Context, Poll};
 
 use anyhow::{bail, format_err, Error};
 use futures::*;
-use http::Uri;
-use http::{Request, Response};
+use hyper::http::Uri;
+use hyper::http::{Request, Response};
 use hyper::client::connect::{Connected, Connection};
 use hyper::client::Client;
 use hyper::Body;
diff --git a/proxmox-restore-daemon/Cargo.toml b/proxmox-restore-daemon/Cargo.toml
index 9d31978b1..bcb50d8ba 100644
--- a/proxmox-restore-daemon/Cargo.toml
+++ b/proxmox-restore-daemon/Cargo.toml
@@ -11,7 +11,6 @@ anyhow.workspace = true
 base64.workspace = true
 env_logger.workspace = true
 futures.workspace = true
-http.workspace = true
 hyper.workspace = true
 libc.workspace = true
 log.workspace = true
diff --git a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
index e0eeca170..8cfc4f13c 100644
--- a/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
+++ b/proxmox-restore-daemon/src/proxmox_restore_daemon/auth.rs
@@ -6,7 +6,7 @@ use std::pin::Pin;
 use std::sync::Arc;
 
 use anyhow::{bail, format_err, Error};
-use http::HeaderMap;
+use hyper::http::HeaderMap;
 use hyper::{Body, Method, Response, StatusCode};
 
 use proxmox_router::UserInformation;
@@ -64,7 +64,7 @@ pub fn check_auth<'a>(
     })
 }
 
-pub fn get_index() -> Pin<Box<dyn Future<Output = http::Response<Body>> + Send>> {
+pub fn get_index() -> Pin<Box<dyn Future<Output = hyper::http::Response<Body>> + Send>> {
     Box::pin(async move {
         let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>";
 
diff --git a/src/acme/plugin.rs b/src/acme/plugin.rs
index 200cf9cc3..c33cfe405 100644
--- a/src/acme/plugin.rs
+++ b/src/acme/plugin.rs
@@ -241,12 +241,12 @@ async fn standalone_respond(
 ) -> Result<Response<Body>, hyper::Error> {
     if req.method() == hyper::Method::GET && req.uri().path() == path.as_str() {
         Ok(Response::builder()
-            .status(http::StatusCode::OK)
+            .status(hyper::http::StatusCode::OK)
             .body(key_auth.as_bytes().to_vec().into())
             .unwrap())
     } else {
         Ok(Response::builder()
-            .status(http::StatusCode::NOT_FOUND)
+            .status(hyper::http::StatusCode::NOT_FOUND)
             .body("Not found.".into())
             .unwrap())
     }
diff --git a/src/api2/backup/mod.rs b/src/api2/backup/mod.rs
index c9ebad498..82c6438aa 100644
--- a/src/api2/backup/mod.rs
+++ b/src/api2/backup/mod.rs
@@ -108,7 +108,7 @@ fn upgrade_to_backup_protocol(
             bail!("invalid protocol name");
         }
 
-        if parts.version >= http::version::Version::HTTP_2 {
+        if parts.version >= hyper::http::version::Version::HTTP_2 {
             bail!(
                 "unexpected http version '{:?}' (expected version < 2)",
                 parts.version
diff --git a/src/api2/node/tasks.rs b/src/api2/node/tasks.rs
index 7fd07f01b..cad740559 100644
--- a/src/api2/node/tasks.rs
+++ b/src/api2/node/tasks.rs
@@ -3,8 +3,8 @@ use std::io::{BufRead, BufReader};
 
 use anyhow::{bail, Error};
 use futures::FutureExt;
-use http::request::Parts;
-use http::{header, Response, StatusCode};
+use hyper::http::request::Parts;
+use hyper::http::{header, Response, StatusCode};
 use hyper::Body;
 use serde_json::{json, Value};
 
diff --git a/src/api2/reader/mod.rs b/src/api2/reader/mod.rs
index 50f80de43..328141c8b 100644
--- a/src/api2/reader/mod.rs
+++ b/src/api2/reader/mod.rs
@@ -106,7 +106,7 @@ fn upgrade_to_backup_reader_protocol(
             bail!("invalid protocol name");
         }
 
-        if parts.version >= http::version::Version::HTTP_2 {
+        if parts.version >= hyper::http::version::Version::HTTP_2 {
             bail!(
                 "unexpected http version '{:?}' (expected version < 2)",
                 parts.version
diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs
index 7a72d49a4..829974d25 100644
--- a/src/bin/proxmox-backup-api.rs
+++ b/src/bin/proxmox-backup-api.rs
@@ -3,7 +3,7 @@ use std::pin::{pin, Pin};
 
 use anyhow::{bail, Error};
 use futures::*;
-use http::Response;
+use hyper::http::Response;
 use hyper::{Body, StatusCode};
 use tracing::level_filters::LevelFilter;
 
diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index ce1be1c0d..e67a3bd22 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -4,8 +4,8 @@ use std::sync::{Arc, Mutex};
 
 use anyhow::{bail, format_err, Context, Error};
 use futures::*;
-use http::request::Parts;
-use http::Response;
+use hyper::http::request::Parts;
+use hyper::http::Response;
 use hyper::header;
 use hyper::{Body, StatusCode};
 use tracing::level_filters::LevelFilter;
@@ -75,7 +75,7 @@ fn main() -> Result<(), Error> {
 
 /// check for a cookie with the user-preferred language, fallback to the config one if not set or
 /// not existing
-fn get_language(headers: &http::HeaderMap) -> String {
+fn get_language(headers: &hyper::http::HeaderMap) -> String {
     let exists = |l: &str| Path::new(&format!("/usr/share/pbs-i18n/pbs-lang-{l}.js")).exists();
 
     match cookie_from_header(headers, "PBSLangCookie") {
@@ -87,7 +87,7 @@ fn get_language(headers: &http::HeaderMap) -> String {
     }
 }
 
-fn get_theme(headers: &http::HeaderMap) -> String {
+fn get_theme(headers: &hyper::http::HeaderMap) -> String {
     let exists = |t: &str| {
         t.len() < 32
             && !t.contains('/')
diff --git a/src/server/auth.rs b/src/server/auth.rs
index f2da10795..1ea449a40 100644
--- a/src/server/auth.rs
+++ b/src/server/auth.rs
@@ -4,7 +4,7 @@ use proxmox_router::UserInformation;
 use pbs_config::CachedUserInfo;
 
 pub async fn check_pbs_auth(
-    headers: &http::HeaderMap,
+    headers: &hyper::http::HeaderMap,
     method: &hyper::Method,
 ) -> Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError> {
     let user_info = CachedUserInfo::new()?;
diff --git a/src/server/sync.rs b/src/server/sync.rs
index 0bd7a7a85..5e3fbdcd7 100644
--- a/src/server/sync.rs
+++ b/src/server/sync.rs
@@ -9,7 +9,7 @@ use std::time::Duration;
 
 use anyhow::{bail, format_err, Context, Error};
 use futures::{future::FutureExt, select};
-use http::StatusCode;
+use hyper::http::StatusCode;
 use serde_json::json;
 use tracing::{info, warn};
 
-- 
2.39.5





More information about the pbs-devel mailing list