public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Max Carrara" <m.carrara@proxmox.com>
To: "Proxmox Backup Server development discussion"
	<pbs-devel@lists.proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox 04/17] http: adapt connector to hyper 1.x
Date: Wed, 02 Apr 2025 15:31:17 +0200	[thread overview]
Message-ID: <D8W6UT4WW2F8.TELZOEMQEGEY@proxmox.com> (raw)
In-Reply-To: <20250326152327.332179-5-f.gruenbichler@proxmox.com>

On Wed Mar 26, 2025 at 4:23 PM CET, Fabian Grünbichler wrote:
> by switching to tower's Service and wrapping in TokioIo as needed. hyper
> now uses their own Service type to not expose tower in their public API,
> and their own Async IO traits, but they provide wrappers to not require
> too many changes for crates like ours here that already used hyper 0.14.
>
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
>  proxmox-http/Cargo.toml              |  9 ++++--
>  proxmox-http/src/client/connector.rs | 44 ++++++++++++++++++----------
>  2 files changed, 36 insertions(+), 17 deletions(-)
>
> diff --git a/proxmox-http/Cargo.toml b/proxmox-http/Cargo.toml
> index c5137e2a..4ec142c9 100644
> --- a/proxmox-http/Cargo.toml
> +++ b/proxmox-http/Cargo.toml
> @@ -25,6 +25,7 @@ tokio = { workspace = true, features = [], optional = true }
>  tokio-openssl = { workspace = true, optional = true }
>  ureq = { version = "2.4", features = ["native-certs", "native-tls"], optional = true, default-features = false }
>  url = { workspace = true, optional = true }
> +tower-service = { workspace = true, optional = true }
>  
>  proxmox-async = { workspace = true, optional = true }
>  proxmox-sys = { workspace = true, optional = true }
> @@ -52,15 +53,19 @@ rate-limited-stream = [
>  client = [
>      "dep:futures",
>      "dep:hyper",
> +    "dep:hyper-util",
>      "dep:openssl",
>      "dep:proxmox-compression",
>      "dep:tokio",
>      "dep:tokio-openssl",
> +    "dep:tower-service",
>      "hyper?/client",
>      "hyper?/http1",
>      "hyper?/http2",
> -    "hyper?/stream",
> -    "hyper?/tcp",
> +    "hyper-util?/client",
> +    "hyper-util?/client-legacy",
> +    "hyper-util?/http1",
> +    "hyper-util?/tokio",
>      "tokio?/io-util",
>      "http-helpers",
>      "rate-limited-stream",
> diff --git a/proxmox-http/src/client/connector.rs b/proxmox-http/src/client/connector.rs
> index 63b9d10c..70421793 100644
> --- a/proxmox-http/src/client/connector.rs
> +++ b/proxmox-http/src/client/connector.rs
> @@ -6,7 +6,8 @@ use std::task::{Context, Poll};
>  
>  use futures::*;
>  use http::Uri;
> -use hyper::client::HttpConnector;
> +use hyper_util::client::legacy::connect::HttpConnector;
> +use hyper_util::rt::TokioIo;
>  use openssl::ssl::SslConnector;
>  use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
>  use tokio::net::TcpStream;
> @@ -122,8 +123,8 @@ impl HttpsConnector {
>      }
>  }
>  
> -impl hyper::service::Service<Uri> for HttpsConnector {
> -    type Response = MaybeTlsStream<RateLimitedStream<TcpStream>>;
> +impl tower_service::Service<Uri> for HttpsConnector {
> +    type Response = TokioIo<MaybeTlsStream<RateLimitedStream<TcpStream>>>;
>      type Error = Error;
>      #[allow(clippy::type_complexity)]
>      type Future =
> @@ -171,9 +172,13 @@ impl hyper::service::Service<Uri> for HttpsConnector {
>              if use_connect {
>                  async move {
>                      use std::fmt::Write as _;
> -                    let tcp_stream = connector.call(proxy_uri).await.map_err(|err| {
> -                        format_err!("error connecting to {} - {}", proxy_authority, err)

The call to `format_err!` above can be shortened by inlining the
parameters, i.e.:

    format_err!("error connecting to {proxy_authority} - {err}")

> -                    })?;
> +                    let tcp_stream = connector
> +                        .call(proxy_uri)
> +                        .await
> +                        .map_err(|err| {
> +                            format_err!("error connecting to {} - {}", proxy_authority, err)

Same here.

> +                        })?
> +                        .into_inner();
>  
>                      let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
>  
> @@ -196,24 +201,30 @@ impl hyper::service::Service<Uri> for HttpsConnector {
>                      Self::parse_connect_response(&mut tcp_stream).await?;
>  
>                      if is_https {
> -                        Self::secure_stream(tcp_stream, &ssl_connector, &host).await
> +                        Self::secure_stream(tcp_stream, &ssl_connector, &host)
> +                            .await
> +                            .map(TokioIo::new)
>                      } else {
> -                        Ok(MaybeTlsStream::Normal(tcp_stream))
> +                        Ok(TokioIo::new(MaybeTlsStream::Normal(tcp_stream)))
>                      }
>                  }
>                  .boxed()
>              } else {
>                  async move {
> -                    let tcp_stream = connector.call(proxy_uri).await.map_err(|err| {
> -                        format_err!("error connecting to {} - {}", proxy_authority, err)

As well as here.

> -                    })?;
> +                    let tcp_stream = connector
> +                        .call(proxy_uri)
> +                        .await
> +                        .map_err(|err| {
> +                            format_err!("error connecting to {} - {}", proxy_authority, err)

And here.

> +                        })?
> +                        .into_inner();
>  
>                      let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
>  
>                      let tcp_stream =
>                          RateLimitedStream::with_limiter(tcp_stream, read_limiter, write_limiter);
>  
> -                    Ok(MaybeTlsStream::Proxied(tcp_stream))
> +                    Ok(TokioIo::new(MaybeTlsStream::Proxied(tcp_stream)))
>                  }
>                  .boxed()
>              }
> @@ -223,7 +234,8 @@ impl hyper::service::Service<Uri> for HttpsConnector {
>                  let tcp_stream = connector
>                      .call(dst)
>                      .await
> -                    .map_err(|err| format_err!("error connecting to {} - {}", dst_str, err))?;
> +                    .map_err(|err| format_err!("error connecting to {} - {}", dst_str, err))?

And here too.

> +                    .into_inner();
>  
>                  let _ = set_tcp_keepalive(tcp_stream.as_raw_fd(), keepalive);
>  
> @@ -231,9 +243,11 @@ impl hyper::service::Service<Uri> for HttpsConnector {
>                      RateLimitedStream::with_limiter(tcp_stream, read_limiter, write_limiter);
>  
>                  if is_https {
> -                    Self::secure_stream(tcp_stream, &ssl_connector, &host).await
> +                    Self::secure_stream(tcp_stream, &ssl_connector, &host)
> +                        .await
> +                        .map(TokioIo::new)
>                  } else {
> -                    Ok(MaybeTlsStream::Normal(tcp_stream))
> +                    Ok(TokioIo::new(MaybeTlsStream::Normal(tcp_stream)))
>                  }
>              }
>              .boxed()



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  reply	other threads:[~2025-04-02 13:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-26 15:23 [pbs-devel] [RFC proxmox 00/23] upgrade to hyper/http 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 01/17] http: order feature values Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 02/17] http: rate-limited-stream: update to hyper/http 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 03/17] http: adapt MaybeTlsStream to hyper 1.x Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 04/17] http: adapt connector " Fabian Grünbichler
2025-04-02 13:31   ` Max Carrara [this message]
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 05/17] http: add Body implementation Fabian Grünbichler
2025-04-02 13:31   ` Max Carrara
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 06/17] http: adapt simple client to hyper 1.x Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 07/17] http: websocket: update to http/hyper 1 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 08/17] openid: use http 0.2 to avoid openidconnect update Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 09/17] proxmox-login: switch to http 1.x Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 10/17] client: switch to hyper/http 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 11/17] metrics: update " Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 12/17] acme: switch to http/hyper 1.0 Fabian Grünbichler
2025-04-02 13:31   ` Max Carrara
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 13/17] proxmox-router: update to hyper 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 14/17] proxmox-rest-server: " Fabian Grünbichler
2025-04-02 13:34   ` Max Carrara
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 15/17] proxmox-rest-server: fix and extend example Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 16/17] proxmox-auth-api: update to hyper 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox 17/17] proxmox-acme-api: " Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 1/6] Revert "h2: switch to legacy feature" Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 2/6] pbs-client: adapt http client to hyper/http 1.0 Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 3/6] pbs-client: vsock: adapt " Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 4/6] restore daemon: " Fabian Grünbichler
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 5/6] " Fabian Grünbichler
2025-04-02 13:36   ` Max Carrara
2025-03-26 15:23 ` [pbs-devel] [PATCH proxmox-backup 6/6] adapt examples " Fabian Grünbichler
2025-04-02 13:53 ` [pbs-devel] [RFC proxmox 00/23] upgrade " Max Carrara
2025-04-03 13:32   ` Max Carrara
2025-04-02 14:39 ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D8W6UT4WW2F8.TELZOEMQEGEY@proxmox.com \
    --to=m.carrara@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal