From da259a8d76319c7eeedbe6c2ba8e98e12761f0a2 Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Fri, 1 Dec 2023 21:18:28 +0100 Subject: [PATCH] Upgrade to hyper 1.0 and hyper-tls 0.6 --- Cargo.toml | 7 +++++-- src/lib.rs | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e33e5c7..3198233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,13 @@ repository = "https://github.com/rnestler/yts-api-rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bytes = "1.5.0" serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" -hyper = { version = "0.14.4", features = ["full"] } -hyper-tls = "0.5.0" +http-body-util = "0.1.0" +hyper = { version = "1.0.1", features = ["full"] } +hyper-util = { version = "0.1.1", features = ["full"] } +hyper-tls = "0.6.0" parse-display = "0.8.2" [dev_dependencies] diff --git a/src/lib.rs b/src/lib.rs index da81d9d..67292d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,9 @@ -use hyper::{body::HttpBody, Client}; +use bytes::Bytes; +use http_body_util::BodyExt; +use http_body_util::Empty; use hyper_tls::HttpsConnector; +use hyper_util::client::legacy::Client; +use hyper_util::rt::TokioExecutor; use parse_display::Display; use serde::{Deserialize, Serialize}; @@ -149,13 +153,15 @@ fn add_query(url: &mut String, name: &str, value: Option) { /// Helper to execute an API endpoint async fn execute(url: &str) -> Result> { let https = HttpsConnector::new(); - let client = Client::builder().build::<_, hyper::Body>(https); + let client = Client::builder(TokioExecutor::new()).build::<_, Empty>(https); let mut res = client.get(url.parse()?).await?; let mut bytes = Vec::new(); - while let Some(next) = res.data().await { - let chunk = next?; - bytes.extend(chunk); + while let Some(frame) = res.body_mut().frame().await { + let frame = frame?; + if let Some(data) = frame.data_ref() { + bytes.extend(data); + } } let body = String::from_utf8(bytes)?; let response: Response = serde_json::from_str(&body)?;