hyper: start preparing upgrade to 1.x

by switching on deprecations and using some backported types already
available on 0.14:

- use body::HttpBody::collect() instead of to_bytes() directly on Body
- use server::conn::http2::Builder instead of server::conn::Http with
  http2_only

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2025-03-13 12:00:13 +01:00
parent 168ed37026
commit 6565199af4
6 changed files with 20 additions and 24 deletions

View File

@ -127,7 +127,7 @@ futures = "0.3"
h2 = { version = "0.4", features = [ "legacy", "stream" ] } h2 = { version = "0.4", features = [ "legacy", "stream" ] }
handlebars = "3.0" handlebars = "3.0"
hex = "0.4.3" hex = "0.4.3"
hyper = { version = "0.14", features = [ "full" ] } hyper = { version = "0.14", features = [ "backports", "deprecated", "full" ] }
libc = "0.2" libc = "0.2"
log = "0.4.17" log = "0.4.17"
nix = "0.26.1" nix = "0.26.1"

View File

@ -8,7 +8,7 @@ use hyper::client::{Client, HttpConnector};
use hyper::http::header::HeaderValue; use hyper::http::header::HeaderValue;
use hyper::http::Uri; use hyper::http::Uri;
use hyper::http::{Request, Response}; use hyper::http::{Request, Response};
use hyper::Body; use hyper::{body::HttpBody, Body};
use openssl::{ use openssl::{
ssl::{SslConnector, SslMethod}, ssl::{SslConnector, SslMethod},
x509::X509StoreContextRef, x509::X509StoreContextRef,
@ -706,8 +706,7 @@ impl HttpClient {
.map(|_| Err(format_err!("unknown error"))) .map(|_| Err(format_err!("unknown error")))
.await? .await?
} else { } else {
resp.into_body() futures::TryStreamExt::map_err(resp.into_body(), Error::from)
.map_err(Error::from)
.try_fold(output, move |acc, chunk| async move { .try_fold(output, move |acc, chunk| async move {
acc.write_all(&chunk)?; acc.write_all(&chunk)?;
Ok::<_, Error>(acc) Ok::<_, Error>(acc)
@ -844,7 +843,7 @@ impl HttpClient {
async fn api_response(response: Response<Body>) -> Result<Value, Error> { async fn api_response(response: Response<Body>) -> Result<Value, Error> {
let status = response.status(); let status = response.status();
let data = hyper::body::to_bytes(response.into_body()).await?; let data = HttpBody::collect(response.into_body()).await?.to_bytes();
let text = String::from_utf8(data.to_vec()).unwrap(); let text = String::from_utf8(data.to_vec()).unwrap();
if status.is_success() { if status.is_success() {

View File

@ -7,7 +7,7 @@ use hyper::client::connect::{Connected, Connection};
use hyper::client::Client; use hyper::client::Client;
use hyper::http::Uri; use hyper::http::Uri;
use hyper::http::{Request, Response}; use hyper::http::{Request, Response};
use hyper::Body; use hyper::{body::HttpBody, Body};
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use serde_json::Value; use serde_json::Value;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf}; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
@ -179,8 +179,7 @@ impl VsockClient {
if !status.is_success() { if !status.is_success() {
Self::api_response(resp).await.map(|_| ())? Self::api_response(resp).await.map(|_| ())?
} else { } else {
resp.into_body() futures::TryStreamExt::map_err(resp.into_body(), Error::from)
.map_err(Error::from)
.try_fold(output, move |acc, chunk| async move { .try_fold(output, move |acc, chunk| async move {
acc.write_all(&chunk).await?; acc.write_all(&chunk).await?;
Ok::<_, Error>(acc) Ok::<_, Error>(acc)
@ -192,7 +191,7 @@ impl VsockClient {
async fn api_response(response: Response<Body>) -> Result<Value, Error> { async fn api_response(response: Response<Body>) -> Result<Value, Error> {
let status = response.status(); let status = response.status();
let data = hyper::body::to_bytes(response.into_body()).await?; let data = HttpBody::collect(response.into_body()).await?.to_bytes();
let text = String::from_utf8(data.to_vec()).unwrap(); let text = String::from_utf8(data.to_vec()).unwrap();
if status.is_success() { if status.is_success() {

View File

@ -6,7 +6,7 @@ use std::os::unix::fs::OpenOptionsExt;
use anyhow::{bail, format_err}; use anyhow::{bail, format_err};
use bytes::Bytes; use bytes::Bytes;
use hyper::{Body, Request}; use hyper::{body::HttpBody, Body, Request};
use nix::sys::stat::Mode; use nix::sys::stat::Mode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -508,9 +508,11 @@ impl AcmeClient {
let (parts, body) = response.into_parts(); let (parts, body) = response.into_parts();
let status = parts.status.as_u16(); let status = parts.status.as_u16();
let body = hyper::body::to_bytes(body) let body = body
.collect()
.await .await
.map_err(|err| Error::Custom(format!("failed to retrieve response body: {}", err)))?; .map_err(|err| Error::Custom(format!("failed to retrieve response body: {}", err)))?
.to_bytes();
let got_nonce = if let Some(new_nonce) = parts.headers.get(proxmox_acme::REPLAY_NONCE) { let got_nonce = if let Some(new_nonce) = parts.headers.get(proxmox_acme::REPLAY_NONCE) {
let new_nonce = new_nonce.to_str().map_err(|err| { let new_nonce = new_nonce.to_str().map_err(|err| {

View File

@ -239,14 +239,12 @@ fn upgrade_to_backup_protocol(
.and_then(move |conn| { .and_then(move |conn| {
env2.debug("protocol upgrade done"); env2.debug("protocol upgrade done");
let mut http = hyper::server::conn::Http::new() let mut http = hyper::server::conn::http2::Builder::new(ExecInheritLogContext);
.with_executor(ExecInheritLogContext);
http.http2_only(true);
// increase window size: todo - find optiomal size // increase window size: todo - find optiomal size
let window_size = 32 * 1024 * 1024; // max = (1 << 31) - 2 let window_size = 32 * 1024 * 1024; // max = (1 << 31) - 2
http.http2_initial_stream_window_size(window_size); http.initial_stream_window_size(window_size);
http.http2_initial_connection_window_size(window_size); http.initial_connection_window_size(window_size);
http.http2_max_frame_size(4 * 1024 * 1024); http.max_frame_size(4 * 1024 * 1024);
let env3 = env2.clone(); let env3 = env2.clone();
http.serve_connection(conn, service).map(move |result| { http.serve_connection(conn, service).map(move |result| {

View File

@ -183,14 +183,12 @@ fn upgrade_to_backup_reader_protocol(
let conn = hyper::upgrade::on(Request::from_parts(parts, req_body)).await?; let conn = hyper::upgrade::on(Request::from_parts(parts, req_body)).await?;
env2.debug("protocol upgrade done"); env2.debug("protocol upgrade done");
let mut http = let mut http = hyper::server::conn::http2::Builder::new(ExecInheritLogContext);
hyper::server::conn::Http::new().with_executor(ExecInheritLogContext);
http.http2_only(true);
// increase window size: todo - find optiomal size // increase window size: todo - find optiomal size
let window_size = 32 * 1024 * 1024; // max = (1 << 31) - 2 let window_size = 32 * 1024 * 1024; // max = (1 << 31) - 2
http.http2_initial_stream_window_size(window_size); http.initial_stream_window_size(window_size);
http.http2_initial_connection_window_size(window_size); http.initial_connection_window_size(window_size);
http.http2_max_frame_size(4 * 1024 * 1024); http.max_frame_size(4 * 1024 * 1024);
http.serve_connection(conn, service) http.serve_connection(conn, service)
.map_err(Error::from) .map_err(Error::from)