Skip to content

Commit

Permalink
Merge pull request #14 from rnestler/upgrade-to-hyper-1.0
Browse files Browse the repository at this point in the history
Upgrade to hyper 1.0 and hyper-tls 0.6
  • Loading branch information
rnestler authored Jan 3, 2024
2 parents a6a2f25 + ff61c80 commit 37a3d29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Update parse-display dependency to 0.8
* Update hyper dependency to 1.0
* Bump MSRV to 1.65

## [0.3.0] - 2023-04-04
Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -149,13 +153,15 @@ fn add_query(url: &mut String, name: &str, value: Option<impl fmt::Display>) {
/// Helper to execute an API endpoint
async fn execute(url: &str) -> Result<Data, Box<dyn std::error::Error + Send + Sync>> {
let https = HttpsConnector::new();
let client = Client::builder().build::<_, hyper::Body>(https);
let client = Client::builder(TokioExecutor::new()).build::<_, Empty<Bytes>>(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)?;
Expand Down

0 comments on commit 37a3d29

Please sign in to comment.