Skip to content

Commit

Permalink
Upgrade reqwest to v0.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 5, 2024
1 parent 0093404 commit b5903f0
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 620 deletions.
530 changes: 230 additions & 300 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ anyhow = { version = "1.0.80" }
async-channel = { version = "2.2.0" }
async-compression = { version = "0.4.6" }
async-trait = { version = "0.1.78" }
async_http_range_reader = { version = "0.7.0" }
async_http_range_reader = { git = "https://github.com/charliermarsh/async_http_range_reader", rev = "c38657c9ece7970830dc850d860664640271bf7b" }
async_zip = { git = "https://github.com/charliermarsh/rs-async-zip", rev = "1dcb40cfe1bf5325a6fd4bfcf9894db40241f585", features = ["deflate"] }
axoupdater = { version = "0.3.1", default-features = false }
backoff = { version = "0.4.0" }
Expand Down Expand Up @@ -85,7 +85,7 @@ hex = { version = "0.4.3" }
hmac = { version = "0.12.1" }
home = { version = "0.5.9" }
html-escape = { version = "0.2.13" }
http = { version = "0.2.12" }
http = { version = "1.1.0" }
indexmap = { version = "2.2.5" }
indicatif = { version = "0.17.7" }
indoc = { version = "2.0.4" }
Expand All @@ -106,9 +106,9 @@ rand = { version = "0.8.5" }
rayon = { version = "1.8.0" }
reflink-copy = { version = "0.1.15" }
regex = { version = "1.10.2" }
reqwest = { version = "0.11.23", default-features = false, features = ["json", "gzip", "brotli", "stream", "rustls-tls", "rustls-tls-native-roots"] }
reqwest-middleware = { version = "0.2.4" }
reqwest-retry = { version = "0.3.0" }
reqwest = { version = "0.12.3", default-features = false, features = ["json", "gzip", "brotli", "stream", "rustls-tls", "rustls-tls-native-roots"] }
reqwest-middleware = { version = "0.3.0" }
reqwest-retry = { version = "0.5.0" }
rkyv = { version = "0.7.43", features = ["strict", "validation"] }
rmp-serde = { version = "1.1.2" }
rust-netrc = { version = "0.1.1" }
Expand Down Expand Up @@ -149,6 +149,9 @@ zip = { version = "0.6.6", default-features = false, features = ["deflate"] }
# For pyproject-toml
pep440_rs = { path = "crates/pep440-rs" }
pep508_rs = { path = "crates/pep508-rs" }
# For reqwest
reqwest-middleware = { git = "https://github.com/TrueLayer/reqwest-middleware", rev = "938a3a0e3c6a1d49462f36826a5bb3b100b8e161" }
reqwest-retry = { git = "https://github.com/TrueLayer/reqwest-middleware", rev = "938a3a0e3c6a1d49462f36826a5bb3b100b8e161" }

[workspace.lints.rust]
unsafe_code = "warn"
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ edition = "2021"
async-trait = { workspace = true }
base64 = { workspace = true }
clap = { workspace = true, features = ["derive", "env"], optional = true }
http = { workspace = true }
once_cell = { workspace = true }
reqwest = { workspace = true }
reqwest-middleware = { workspace = true }
rust-netrc = { workspace = true }
task-local-extensions = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
once_cell = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-auth/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use http::Extensions;
use std::path::Path;

use netrc::Netrc;
use reqwest::{header::HeaderValue, Request, Response};
use reqwest_middleware::{Middleware, Next};
use task_local_extensions::Extensions;
use tracing::{debug, warn};

use crate::{
Expand Down
9 changes: 3 additions & 6 deletions crates/uv-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ tracing = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }

# These must be kept in-sync with those used by `reqwest`.
rustls = { version = "0.21.10" }
rustls-native-certs = { version = "0.6.3" }
webpki-roots = { version = "0.25.4" }

[dev-dependencies]
anyhow = { workspace = true }
hyper = { version = "0.14.28", features = ["server", "http1"] }
http-body-util = { version = "0.1.0" }
hyper = { version = "1.2.0", features = ["server", "http1"] }
hyper-util = { version = "0.1.3", features = ["tokio"] }
insta = { version = "1.36.1" }
os_info = { version = "3.7.0", default-features = false }
tokio = { workspace = true, features = ["fs", "macros"] }
20 changes: 10 additions & 10 deletions crates/uv-client/src/base_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use uv_warnings::warn_user_once;

use crate::linehaul::LineHaul;
use crate::middleware::OfflineMiddleware;
use crate::tls::Roots;
use crate::{tls, Connectivity};
use crate::Connectivity;

/// A builder for an [`RegistryClient`].
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -140,19 +139,20 @@ impl<'a> BaseClientBuilder<'a> {
}
path_exists
});
// Load the TLS configuration.
let tls = tls::load(if self.native_tls || ssl_cert_file_exists {
Roots::Native
} else {
Roots::Webpki
})
.expect("Failed to load TLS configuration.");

// Configure the builder.
let client_core = ClientBuilder::new()
.user_agent(user_agent_string)
.pool_max_idle_per_host(20)
.timeout(std::time::Duration::from_secs(timeout))
.use_preconfigured_tls(tls);
.tls_built_in_root_certs(false);

// Configure TLS.
let client_core = if self.native_tls || ssl_cert_file_exists {
client_core.tls_built_in_native_certs(true)
} else {
client_core.tls_built_in_webpki_certs(true)
};

client_core.build().expect("Failed to build HTTP client.")
});
Expand Down
1 change: 0 additions & 1 deletion crates/uv-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ mod middleware;
mod registry_client;
mod remote_metadata;
mod rkyvutil;
mod tls;
2 changes: 1 addition & 1 deletion crates/uv-client/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use http::Extensions;
use std::fmt::Debug;

use reqwest::{Request, Response};
use reqwest_middleware::{Middleware, Next};
use task_local_extensions::Extensions;
use url::Url;

/// A custom error type for the offline middleware.
Expand Down
102 changes: 0 additions & 102 deletions crates/uv-client/src/tls.rs

This file was deleted.

30 changes: 18 additions & 12 deletions crates/uv-client/tests/netrc_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ use std::io::Write;

use anyhow::Result;
use futures::future;
use hyper::header::AUTHORIZATION;
use hyper::server::conn::Http;
use http::header::AUTHORIZATION;
use http_body_util::Full;
use hyper::body::Bytes;
use hyper::server::conn::http1;
use hyper::service::service_fn;
use hyper::{Body, Request, Response};
use hyper::{Request, Response};
use hyper_util::rt::TokioIo;
use tempfile::NamedTempFile;
use tokio::net::TcpListener;

Expand All @@ -21,24 +24,27 @@ async fn test_client_with_netrc_credentials() -> Result<()> {

// Spawn the server loop in a background task
tokio::spawn(async move {
let svc = service_fn(move |req: Request<Body>| {
let svc = service_fn(move |req: Request<hyper::body::Incoming>| {
// Get User Agent Header and send it back in the response
let auth = req
.headers()
.get(AUTHORIZATION)
.and_then(|v| v.to_str().ok())
.map(|s| s.to_string())
.unwrap_or_default(); // Empty Default
future::ok::<_, hyper::Error>(Response::new(Body::from(auth)))
future::ok::<_, hyper::Error>(Response::new(Full::new(Bytes::from(auth))))
});
// Start Hyper Server
// Start Server (not wrapped in loop {} since we want a single response server)
// If you want server to accept multiple connections, wrap it in loop {}
let (socket, _) = listener.accept().await.unwrap();
Http::new()
.http1_keep_alive(false)
.serve_connection(socket, svc)
.with_upgrades()
.await
.expect("Server Started");
let socket = TokioIo::new(socket);
tokio::task::spawn(async move {
http1::Builder::new()
.serve_connection(socket, svc)
.with_upgrades()
.await
.expect("Server Started");
});
});

// Create a netrc file
Expand Down
Loading

0 comments on commit b5903f0

Please sign in to comment.