cargo: drop direct http crate dependency, tree-wide namespace fix

Instead of using and depending on the `http` crate 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@proxmox.com>
This commit is contained in:
Christian Ebner 2025-01-21 13:54:58 +01:00 committed by Thomas Lamprecht
parent d910543d56
commit d93d782d37
18 changed files with 33 additions and 31 deletions

View File

@ -127,7 +127,6 @@ futures = "0.3"
h2 = { version = "0.4", features = [ "stream" ] } h2 = { version = "0.4", features = [ "stream" ] }
handlebars = "3.0" handlebars = "3.0"
hex = "0.4.3" hex = "0.4.3"
http = "0.2"
hyper = { version = "0.14", features = [ "full" ] } hyper = { version = "0.14", features = [ "full" ] }
libc = "0.2" libc = "0.2"
log = "0.4.17" log = "0.4.17"
@ -174,7 +173,6 @@ endian_trait.workspace = true
futures.workspace = true futures.workspace = true
h2.workspace = true h2.workspace = true
hex.workspace = true hex.workspace = true
http.workspace = true
hyper.workspace = true hyper.workspace = true
libc.workspace = true libc.workspace = true
log.workspace = true log.workspace = true

View File

@ -54,7 +54,7 @@ fn send_request(
) -> impl Future<Output = Result<usize, Error>> { ) -> impl Future<Output = Result<usize, Error>> {
println!("sending request"); println!("sending request");
let request = http::Request::builder() let request = hyper::http::Request::builder()
.uri("http://localhost/") .uri("http://localhost/")
.body(()) .body(())
.unwrap(); .unwrap();

View File

@ -54,7 +54,7 @@ fn send_request(
) -> impl Future<Output = Result<usize, Error>> { ) -> impl Future<Output = Result<usize, Error>> {
println!("sending request"); println!("sending request");
let request = http::Request::builder() let request = hyper::http::Request::builder()
.uri("http://localhost/") .uri("http://localhost/")
.body(()) .body(())
.unwrap(); .unwrap();

View File

@ -63,8 +63,11 @@ async fn handle_connection(socket: TcpStream, acceptor: Arc<SslAcceptor>) -> Res
let body = Body::from(buffer); let body = Body::from(buffer);
let response = Response::builder() let response = Response::builder()
.status(http::StatusCode::OK) .status(hyper::http::StatusCode::OK)
.header(http::header::CONTENT_TYPE, "application/octet-stream") .header(
hyper::http::header::CONTENT_TYPE,
"application/octet-stream",
)
.body(body) .body(body)
.unwrap(); .unwrap();
future::ok::<_, Error>(response) future::ok::<_, Error>(response)

View File

@ -39,8 +39,11 @@ async fn handle_connection(socket: TcpStream) -> Result<(), Error> {
let body = Body::from(buffer); let body = Body::from(buffer);
let response = Response::builder() let response = Response::builder()
.status(http::StatusCode::OK) .status(hyper::http::StatusCode::OK)
.header(http::header::CONTENT_TYPE, "application/octet-stream") .header(
hyper::http::header::CONTENT_TYPE,
"application/octet-stream",
)
.body(body) .body(body)
.unwrap(); .unwrap();
future::ok::<_, Error>(response) future::ok::<_, Error>(response)

View File

@ -12,7 +12,6 @@ bytes.workspace = true
futures.workspace = true futures.workspace = true
h2.workspace = true h2.workspace = true
hex.workspace = true hex.workspace = true
http.workspace = true
hyper.workspace = true hyper.workspace = true
libc.workspace = true libc.workspace = true
nix.workspace = true nix.workspace = true

View File

@ -4,10 +4,10 @@ use std::time::Duration;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use futures::*; use futures::*;
use http::header::HeaderValue;
use http::Uri;
use http::{Request, Response};
use hyper::client::{Client, HttpConnector}; use hyper::client::{Client, HttpConnector};
use hyper::http::header::HeaderValue;
use hyper::http::Uri;
use hyper::http::{Request, Response};
use hyper::Body; use hyper::Body;
use openssl::{ use openssl::{
ssl::{SslConnector, SslMethod}, ssl::{SslConnector, SslMethod},
@ -782,7 +782,7 @@ impl HttpClient {
.map_err(|_| format_err!("http upgrade request timed out"))??; .map_err(|_| format_err!("http upgrade request timed out"))??;
let status = resp.status(); let status = resp.status();
if status != http::StatusCode::SWITCHING_PROTOCOLS { if status != hyper::http::StatusCode::SWITCHING_PROTOCOLS {
Self::api_response(resp).await?; Self::api_response(resp).await?;
bail!("unknown error"); bail!("unknown error");
} }

View File

@ -3,10 +3,10 @@ use std::task::{Context, Poll};
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use futures::*; use futures::*;
use http::Uri;
use http::{Request, Response};
use hyper::client::connect::{Connected, Connection}; use hyper::client::connect::{Connected, Connection};
use hyper::client::Client; use hyper::client::Client;
use hyper::http::Uri;
use hyper::http::{Request, Response};
use hyper::Body; use hyper::Body;
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use serde_json::Value; use serde_json::Value;

View File

@ -11,7 +11,6 @@ anyhow.workspace = true
base64.workspace = true base64.workspace = true
env_logger.workspace = true env_logger.workspace = true
futures.workspace = true futures.workspace = true
http.workspace = true
hyper.workspace = true hyper.workspace = true
libc.workspace = true libc.workspace = true
log.workspace = true log.workspace = true

View File

@ -6,7 +6,7 @@ use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use anyhow::{bail, format_err, Error}; use anyhow::{bail, format_err, Error};
use http::HeaderMap; use hyper::http::HeaderMap;
use hyper::{Body, Method, Response, StatusCode}; use hyper::{Body, Method, Response, StatusCode};
use proxmox_router::UserInformation; 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 { Box::pin(async move {
let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>"; let index = "<center><h1>Proxmox Backup Restore Daemon/h1></center>";

View File

@ -241,12 +241,12 @@ async fn standalone_respond(
) -> Result<Response<Body>, hyper::Error> { ) -> Result<Response<Body>, hyper::Error> {
if req.method() == hyper::Method::GET && req.uri().path() == path.as_str() { if req.method() == hyper::Method::GET && req.uri().path() == path.as_str() {
Ok(Response::builder() Ok(Response::builder()
.status(http::StatusCode::OK) .status(hyper::http::StatusCode::OK)
.body(key_auth.as_bytes().to_vec().into()) .body(key_auth.as_bytes().to_vec().into())
.unwrap()) .unwrap())
} else { } else {
Ok(Response::builder() Ok(Response::builder()
.status(http::StatusCode::NOT_FOUND) .status(hyper::http::StatusCode::NOT_FOUND)
.body("Not found.".into()) .body("Not found.".into())
.unwrap()) .unwrap())
} }

View File

@ -108,7 +108,7 @@ fn upgrade_to_backup_protocol(
bail!("invalid protocol name"); bail!("invalid protocol name");
} }
if parts.version >= http::version::Version::HTTP_2 { if parts.version >= hyper::http::version::Version::HTTP_2 {
bail!( bail!(
"unexpected http version '{:?}' (expected version < 2)", "unexpected http version '{:?}' (expected version < 2)",
parts.version parts.version

View File

@ -3,8 +3,8 @@ use std::io::{BufRead, BufReader};
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use futures::FutureExt; use futures::FutureExt;
use http::request::Parts; use hyper::http::request::Parts;
use http::{header, Response, StatusCode}; use hyper::http::{header, Response, StatusCode};
use hyper::Body; use hyper::Body;
use serde_json::{json, Value}; use serde_json::{json, Value};

View File

@ -106,7 +106,7 @@ fn upgrade_to_backup_reader_protocol(
bail!("invalid protocol name"); bail!("invalid protocol name");
} }
if parts.version >= http::version::Version::HTTP_2 { if parts.version >= hyper::http::version::Version::HTTP_2 {
bail!( bail!(
"unexpected http version '{:?}' (expected version < 2)", "unexpected http version '{:?}' (expected version < 2)",
parts.version parts.version

View File

@ -3,7 +3,7 @@ use std::pin::{pin, Pin};
use anyhow::{bail, Error}; use anyhow::{bail, Error};
use futures::*; use futures::*;
use http::Response; use hyper::http::Response;
use hyper::{Body, StatusCode}; use hyper::{Body, StatusCode};
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;

View File

@ -4,9 +4,9 @@ use std::sync::{Arc, Mutex};
use anyhow::{bail, format_err, Context, Error}; use anyhow::{bail, format_err, Context, Error};
use futures::*; use futures::*;
use http::request::Parts;
use http::Response;
use hyper::header; use hyper::header;
use hyper::http::request::Parts;
use hyper::http::Response;
use hyper::{Body, StatusCode}; use hyper::{Body, StatusCode};
use tracing::level_filters::LevelFilter; use tracing::level_filters::LevelFilter;
use tracing::{info, warn}; use tracing::{info, warn};
@ -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 /// check for a cookie with the user-preferred language, fallback to the config one if not set or
/// not existing /// 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(); let exists = |l: &str| Path::new(&format!("/usr/share/pbs-i18n/pbs-lang-{l}.js")).exists();
match cookie_from_header(headers, "PBSLangCookie") { 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| { let exists = |t: &str| {
t.len() < 32 t.len() < 32
&& !t.contains('/') && !t.contains('/')

View File

@ -4,7 +4,7 @@ use proxmox_router::UserInformation;
use pbs_config::CachedUserInfo; use pbs_config::CachedUserInfo;
pub async fn check_pbs_auth( pub async fn check_pbs_auth(
headers: &http::HeaderMap, headers: &hyper::http::HeaderMap,
method: &hyper::Method, method: &hyper::Method,
) -> Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError> { ) -> Result<(String, Box<dyn UserInformation + Sync + Send>), AuthError> {
let user_info = CachedUserInfo::new()?; let user_info = CachedUserInfo::new()?;

View File

@ -9,7 +9,7 @@ use std::time::Duration;
use anyhow::{bail, format_err, Context, Error}; use anyhow::{bail, format_err, Context, Error};
use futures::{future::FutureExt, select}; use futures::{future::FutureExt, select};
use http::StatusCode; use hyper::http::StatusCode;
use serde_json::json; use serde_json::json;
use tracing::{info, warn}; use tracing::{info, warn};