From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 6/6] adapt examples to hyper/http 1.0
Date: Wed, 26 Mar 2025 16:23:27 +0100 [thread overview]
Message-ID: <20250326152327.332179-24-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20250326152327.332179-1-f.gruenbichler@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
examples/h2s-server.rs | 28 +++++++++-------------------
examples/h2server.rs | 28 ++++++++--------------------
2 files changed, 17 insertions(+), 39 deletions(-)
diff --git a/examples/h2s-server.rs b/examples/h2s-server.rs
index 0f4c0c145..2f15b0127 100644
--- a/examples/h2s-server.rs
+++ b/examples/h2s-server.rs
@@ -1,26 +1,16 @@
use std::sync::Arc;
use anyhow::{format_err, Error};
-use futures::*;
-use hyper::{Body, Request, Response};
+use bytes::Bytes;
+use futures::{future, FutureExt, TryFutureExt};
+use http_body_util::Full;
+use hyper::{body::Incoming, Request, Response};
+use hyper_util::rt::{TokioExecutor, TokioIo};
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
use tokio::net::{TcpListener, TcpStream};
use pbs_buildcfg::configdir;
-#[derive(Clone, Copy)]
-struct H2SExecutor;
-
-impl<Fut> hyper::rt::Executor<Fut> for H2SExecutor
-where
- Fut: Future + Send + 'static,
- Fut::Output: Send,
-{
- fn execute(&self, fut: Fut) {
- tokio::spawn(fut);
- }
-}
-
fn main() -> Result<(), Error> {
proxmox_async::runtime::main(run())
}
@@ -63,16 +53,16 @@ async fn handle_connection(socket: TcpStream, acceptor: Arc<SslAcceptor>) -> Res
stream.as_mut().accept().await?;
- let mut http = hyper::server::conn::http2::Builder::new(H2SExecutor);
+ let mut http = hyper::server::conn::http2::Builder::new(TokioExecutor::new());
// increase window size: todo - find optiomal size
let max_window_size = (1 << 31) - 2;
http.initial_stream_window_size(max_window_size);
http.initial_connection_window_size(max_window_size);
- let service = hyper::service::service_fn(|_req: Request<Body>| {
+ let service = hyper::service::service_fn(|_req: Request<Incoming>| {
println!("Got request");
let buffer = vec![65u8; 4 * 1024 * 1024]; // nonsense [A,A,A,A...]
- let body = Body::from(buffer);
+ let body = Full::<Bytes>::from(buffer);
let response = Response::builder()
.status(hyper::http::StatusCode::OK)
@@ -85,7 +75,7 @@ async fn handle_connection(socket: TcpStream, acceptor: Arc<SslAcceptor>) -> Res
future::ok::<_, Error>(response)
});
- http.serve_connection(stream, service)
+ http.serve_connection(TokioIo::new(stream), service)
.map_err(Error::from)
.await?;
diff --git a/examples/h2server.rs b/examples/h2server.rs
index 6b286e787..2c368810d 100644
--- a/examples/h2server.rs
+++ b/examples/h2server.rs
@@ -1,24 +1,12 @@
-use std::future::Future;
-
use anyhow::Error;
+use bytes::Bytes;
use futures::*;
-use hyper::{Body, Request, Response};
+use http_body_util::Full;
+use hyper::{body::Incoming, Request, Response};
+use hyper_util::rt::{TokioExecutor, TokioIo};
use tokio::net::{TcpListener, TcpStream};
-#[derive(Clone, Copy)]
-struct H2Executor;
-
-impl<Fut> hyper::rt::Executor<Fut> for H2Executor
-where
- Fut: Future + Send + 'static,
- Fut::Output: Send,
-{
- fn execute(&self, fut: Fut) {
- tokio::spawn(fut);
- }
-}
-
fn main() -> Result<(), Error> {
proxmox_async::runtime::main(run())
}
@@ -41,16 +29,16 @@ async fn run() -> Result<(), Error> {
async fn handle_connection(socket: TcpStream) -> Result<(), Error> {
socket.set_nodelay(true).unwrap();
- let mut http = hyper::server::conn::http2::Builder::new(H2Executor);
+ let mut http = hyper::server::conn::http2::Builder::new(TokioExecutor::new());
// increase window size: todo - find optiomal size
let max_window_size = (1 << 31) - 2;
http.initial_stream_window_size(max_window_size);
http.initial_connection_window_size(max_window_size);
- let service = hyper::service::service_fn(|_req: Request<Body>| {
+ let service = hyper::service::service_fn(|_req: Request<Incoming>| {
println!("Got request");
let buffer = vec![65u8; 4 * 1024 * 1024]; // nonsense [A,A,A,A...]
- let body = Body::from(buffer);
+ let body = Full::<Bytes>::from(buffer);
let response = Response::builder()
.status(hyper::http::StatusCode::OK)
@@ -63,7 +51,7 @@ async fn handle_connection(socket: TcpStream) -> Result<(), Error> {
future::ok::<_, Error>(response)
});
- http.serve_connection(socket, service)
+ http.serve_connection(TokioIo::new(socket), service)
.map_err(Error::from)
.await?;
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-03-26 15:24 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 " 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
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 ` Fabian Grünbichler [this message]
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=20250326152327.332179-24-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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