From 98a97588d3692dc6413bb151f16b7c620179b830 Mon Sep 17 00:00:00 2001 From: George Hahn Date: Thu, 6 Jun 2024 00:47:02 -0600 Subject: [PATCH] Enable deprecation warnings and address --- audio/Cargo.toml | 2 +- audio/src/fetch/receive.rs | 4 ++-- core/Cargo.toml | 2 +- core/src/http_client.rs | 10 +++------- discovery/Cargo.toml | 2 +- discovery/src/server.rs | 5 ++--- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/audio/Cargo.toml b/audio/Cargo.toml index 94b900c7..2740616c 100644 --- a/audio/Cargo.toml +++ b/audio/Cargo.toml @@ -19,7 +19,7 @@ bytes = "1" ctr = "0.9" futures-core = "0.3" futures-util = "0.3" -hyper = { version = "0.14", features = ["client"] } +hyper = { version = "0.14", features = ["client", "backports", "deprecated"] } log = "0.4" parking_lot = { version = "0.12", features = ["deadlock_detection"] } tempfile = "3" diff --git a/audio/src/fetch/receive.rs b/audio/src/fetch/receive.rs index 0b001113..c5e2456c 100644 --- a/audio/src/fetch/receive.rs +++ b/audio/src/fetch/receive.rs @@ -7,7 +7,7 @@ use std::{ use bytes::Bytes; use futures_util::StreamExt; -use hyper::StatusCode; +use hyper::{body::HttpBody, StatusCode}; use tempfile::NamedTempFile; use tokio::sync::{mpsc, oneshot}; @@ -97,7 +97,7 @@ async fn receive_data( } let body = response.into_body(); - let data = match hyper::body::to_bytes(body).await { + let data = match body.collect().await.map(|b| b.to_bytes()) { Ok(bytes) => bytes, Err(e) => break Err(e.into()), }; diff --git a/core/Cargo.toml b/core/Cargo.toml index 2f515480..e6e45f94 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -26,7 +26,7 @@ governor = { version = "0.6", default-features = false, features = ["std", "jitt hmac = "0.12" httparse = "1.7" http = "0.2" -hyper = { version = "0.14", features = ["client", "http1", "http2", "tcp"] } +hyper = { version = "0.14", features = ["client", "http1", "http2", "tcp", "backports", "deprecated"] } hyper-proxy = { version = "0.9", default-features = false, features = ["rustls"] } hyper-rustls = { version = "0.24", features = ["http2"] } log = "0.4" diff --git a/core/src/http_client.rs b/core/src/http_client.rs index 14efdcdf..aec65d4d 100644 --- a/core/src/http_client.rs +++ b/core/src/http_client.rs @@ -11,9 +11,7 @@ use governor::{ }; use http::{header::HeaderValue, Uri}; use hyper::{ - client::{HttpConnector, ResponseFuture}, - header::USER_AGENT, - Body, Client, HeaderMap, Request, Response, StatusCode, + body::HttpBody, client::{HttpConnector, ResponseFuture}, header::USER_AGENT, Body, Client, HeaderMap, Request, Response, StatusCode }; use hyper_proxy::{Intercept, Proxy, ProxyConnector}; use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; @@ -178,9 +176,7 @@ impl HttpClient { // As correct as that may be technically, we now need all this boilerplate to clone it // ourselves, as any `Request` is moved in the loop. let (parts, body) = req.into_parts(); - let body_as_bytes = hyper::body::to_bytes(body) - .await - .unwrap_or_else(|_| Bytes::new()); + let body_as_bytes = body.collect().await.map(|b| b.to_bytes()).unwrap_or_default(); loop { let mut req = Request::builder() @@ -218,7 +214,7 @@ impl HttpClient { pub async fn request_body(&self, req: Request) -> Result { let response = self.request(req).await?; - Ok(hyper::body::to_bytes(response.into_body()).await?) + Ok(response.into_body().collect().await?.to_bytes()) } pub fn request_stream(&self, req: Request) -> Result, Error> { diff --git a/discovery/Cargo.toml b/discovery/Cargo.toml index f4414ebd..396a3f1c 100644 --- a/discovery/Cargo.toml +++ b/discovery/Cargo.toml @@ -18,7 +18,7 @@ form_urlencoded = "1.0" futures-core = "0.3" futures-util = "0.3" hmac = "0.12" -hyper = { version = "0.14", features = ["http1", "server", "tcp"] } +hyper = { version = "0.14", features = ["http1", "server", "tcp", "backports", "deprecated"] } libmdns = "0.8" log = "0.4" rand = "0.8" diff --git a/discovery/src/server.rs b/discovery/src/server.rs index ccdbe685..b1fe6ae0 100644 --- a/discovery/src/server.rs +++ b/discovery/src/server.rs @@ -15,8 +15,7 @@ use futures_core::Stream; use futures_util::{FutureExt, TryFutureExt}; use hmac::{Hmac, Mac}; use hyper::{ - service::{make_service_fn, service_fn}, - Body, Method, Request, Response, StatusCode, + body::HttpBody, service::{make_service_fn, service_fn}, Body, Method, Request, Response, StatusCode }; use log::{debug, error, warn}; @@ -219,7 +218,7 @@ impl RequestHandler { debug!("{:?} {:?} {:?}", parts.method, parts.uri.path(), params); } - let body = hyper::body::to_bytes(body).await?; + let body = body.collect().await?.to_bytes(); params.extend(form_urlencoded::parse(&body));