Skip to content

Commit

Permalink
Update hyper crates
Browse files Browse the repository at this point in the history
  • Loading branch information
lookback-hugotunius committed Jan 16, 2024
1 parent c3d5ba4 commit a0d0d38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
sync = ["ureq"]
async = ["hyper/client", "rustls", "hyper-rustls", "futures", "webpki-roots"]
async = ["hyper", "hyper-util/client-legacy", "hyper-util/http1", "hyper-util/tokio", "rustls", "hyper-rustls", "futures", "webpki-roots"]

[dependencies]
futures = { version = "0.3.21", optional = true }
hyper = { version = "0.14", features = ["client"], optional = true }
hyper-rustls = { version = "0.23.0", optional = true }
hyper = { version = "1.0", features = ["client"], optional = true }
hyper-rustls = { version = "0.26.0", optional = true }
hyper-util = { version = "0.1.2", features = ["client-legacy", "http1", "tokio"], optional = true }
once_cell = "1"
regex = { version = "1" }
rustls = { version = "0.20", optional = true }
# Version set by hyper-rustls
rustls = { version = "*", optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tracing = "0.1"
ureq = { version = "=2.1.0", features = ["json"], optional = true }
webpki-roots = { version = "0.22", optional = true }
webpki-roots = { version = "0.26", optional = true }
35 changes: 18 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ use once_cell::sync::{Lazy, OnceCell};
#[cfg(feature = "async")]
use futures::future;
#[cfg(feature = "async")]
use hyper::{client::HttpConnector, Body, Client, Method, Request};
use hyper::{Method, Request};
#[cfg(feature = "async")]
use rustls::{self, OwnedTrustAnchor, RootCertStore};
use hyper_util::client::legacy::connect::HttpConnector;
#[cfg(feature = "async")]
use hyper_util::client::legacy::Client;
#[cfg(feature = "async")]
use hyper_util::rt::TokioExecutor;
#[cfg(feature = "async")]
use rustls;

Check warning on line 14 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Lint

this import is redundant

#[cfg(any(feature = "async", feature = "sync"))]
use tracing::warn;
Expand Down Expand Up @@ -237,7 +243,7 @@ impl<'a> Series<'a> {
}

#[cfg(feature = "async")]
type HttpClient = Client<hyper_rustls::HttpsConnector<HttpConnector>>;
type HttpClient = Client<hyper_rustls::HttpsConnector<HttpConnector>, String>;

pub struct DDStatsClient {
namespace: String,
Expand Down Expand Up @@ -342,19 +348,14 @@ impl DDStatsClient {

#[cfg(feature = "async")]
{
let mut root_store = RootCertStore::empty();
root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(
|ta| {
OwnedTrustAnchor::from_subject_spki_name_constraints(
ta.subject,
ta.spki,
ta.name_constraints,
)
},
));
let mut root_store = rustls::RootCertStore::empty();
root_store.extend(
webpki_roots::TLS_SERVER_ROOTS
.iter()
.map(|ta| ta.to_owned()),
);

let tls = rustls::ClientConfig::builder()
.with_safe_defaults()
.with_root_certificates(root_store)
.with_no_client_auth();

Expand All @@ -366,7 +367,7 @@ impl DDStatsClient {
.build();

// Build the hyper client from the HTTPS connector.
let http_client: Client<_, hyper::Body> = Client::builder().build(https);
let http_client: Client<_, String> = Client::builder(TokioExecutor::new()).build(https);

DDStatsClient {
namespace: mangle_safe(namespace),
Expand Down Expand Up @@ -557,7 +558,7 @@ impl DDStatsClient {
let req = Request::builder()
.method(Method::POST)
.uri(&api_url)
.body(Body::from(body))
.body(body)
.expect("Build request");

http_client.request(req)
Expand Down Expand Up @@ -596,7 +597,7 @@ impl DDStatsClient {
let req = Request::builder()
.method(Method::POST)
.uri(&api_url)
.body(Body::from(body))
.body(body)
.expect("Build request");

(e.title, client.request(req))
Expand Down

0 comments on commit a0d0d38

Please sign in to comment.