Skip to content

Commit c626da4

Browse files
bartlomiejusbmsr
authored andcommitted
chore: upgrade to reqwest 0.12.4 and rustls 0.22 (denoland#24388)
Reland of denoland#24056 that doesn't suffer from the problem that was discovered in denoland#24261. It uses upgraded `hyper` and `hyper-util` that fixed the previous problem in hyperium/hyper#3691.
1 parent e4fa2e6 commit c626da4

35 files changed

+391
-651
lines changed

Cargo.lock

Lines changed: 101 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ deno_terminal = "0.1.1"
5555
napi_sym = { version = "0.88.0", path = "./cli/napi/sym" }
5656
test_util = { package = "test_server", path = "./tests/util/server" }
5757

58-
denokv_proto = "0.7.0"
59-
denokv_remote = "0.7.0"
58+
denokv_proto = "0.8.1"
59+
denokv_remote = "0.8.1"
6060
# denokv_sqlite brings in bundled sqlite if we don't disable the default features
61-
denokv_sqlite = { default-features = false, version = "0.7.0" }
61+
denokv_sqlite = { default-features = false, version = "0.8.1" }
6262

6363
# exts
6464
deno_broadcast_channel = { version = "0.152.0", path = "./ext/broadcast_channel" }
@@ -118,8 +118,8 @@ http = "1.0"
118118
http-body-util = "0.1"
119119
http_v02 = { package = "http", version = "0.2.9" }
120120
httparse = "1.8.0"
121-
hyper = { version = "=1.1.0", features = ["full"] }
122-
hyper-util = { version = "=0.1.2", features = ["tokio", "server", "server-auto"] }
121+
hyper = { version = "=1.4.0", features = ["full"] }
122+
hyper-util = { version = "=0.1.6", features = ["tokio", "server", "server-auto"] }
123123
hyper_v014 = { package = "hyper", version = "0.14.26", features = ["runtime", "http1"] }
124124
indexmap = { version = "2", features = ["serde"] }
125125
jsonc-parser = { version = "=0.23.0", features = ["serde"] }
@@ -146,14 +146,13 @@ prost = "0.11"
146146
prost-build = "0.11"
147147
rand = "=0.8.5"
148148
regex = "^1.7.0"
149-
reqwest = { version = "=0.11.20", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli", "socks", "json"] } # pinned because of https://github.com/seanmonstar/reqwest/pull/1955
149+
reqwest = { version = "=0.12.4", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli", "socks", "json", "http2"] } # pinned because of https://github.com/seanmonstar/reqwest/pull/1955
150150
ring = "^0.17.0"
151151
rusqlite = { version = "=0.29.0", features = ["unlock_notify", "bundled"] }
152-
# pinned because it was causing issues on cargo publish
153-
rustls = "=0.21.11"
154-
rustls-pemfile = "1.0.0"
155-
rustls-tokio-stream = "=0.2.24"
156-
rustls-webpki = "0.101.4"
152+
rustls = "0.22.4"
153+
rustls-pemfile = "2"
154+
rustls-tokio-stream = "=0.2.23"
155+
rustls-webpki = "0.102"
157156
rustyline = "=13.0.0"
158157
saffron = "=0.1.0"
159158
scopeguard = "1.2.0"
@@ -180,7 +179,7 @@ twox-hash = "=1.6.3"
180179
# Upgrading past 2.4.1 may cause WPT failures
181180
url = { version = "< 2.5.0", features = ["serde", "expose_internals"] }
182181
uuid = { version = "1.3.0", features = ["v4"] }
183-
webpki-roots = "0.25.2"
182+
webpki-roots = "0.26"
184183
zeromq = { version = "=0.3.4", default-features = false, features = ["tcp-transport", "tokio-runtime"] }
185184
zstd = "=0.12.4"
186185

cli/args/mod.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -705,21 +705,13 @@ pub fn get_root_cert_store(
705705
for store in ca_stores.iter() {
706706
match store.as_str() {
707707
"mozilla" => {
708-
root_cert_store.add_trust_anchors(
709-
webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
710-
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(
711-
ta.subject,
712-
ta.spki,
713-
ta.name_constraints,
714-
)
715-
}),
716-
);
708+
root_cert_store.extend(webpki_roots::TLS_SERVER_ROOTS.to_vec());
717709
}
718710
"system" => {
719711
let roots = load_native_certs().expect("could not load platform certs");
720712
for root in roots {
721713
root_cert_store
722-
.add(&rustls::Certificate(root.0))
714+
.add(rustls::pki_types::CertificateDer::from(root.0))
723715
.expect("Failed to add platform cert to root cert store");
724716
}
725717
}
@@ -743,17 +735,17 @@ pub fn get_root_cert_store(
743735
RootCertStoreLoadError::CaFileOpenError(err.to_string())
744736
})?;
745737
let mut reader = BufReader::new(certfile);
746-
rustls_pemfile::certs(&mut reader)
738+
rustls_pemfile::certs(&mut reader).collect::<Result<Vec<_>, _>>()
747739
}
748740
CaData::Bytes(data) => {
749741
let mut reader = BufReader::new(Cursor::new(data));
750-
rustls_pemfile::certs(&mut reader)
742+
rustls_pemfile::certs(&mut reader).collect::<Result<Vec<_>, _>>()
751743
}
752744
};
753745

754746
match result {
755747
Ok(certs) => {
756-
root_cert_store.add_parsable_certificates(&certs);
748+
root_cert_store.add_parsable_certificates(certs);
757749
}
758750
Err(e) => {
759751
return Err(RootCertStoreLoadError::FailedAddPemFile(e.to_string()));

cli/http_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ mod test {
587587
use std::collections::HashSet;
588588
use std::hash::RandomState;
589589

590-
use deno_runtime::deno_tls::RootCertStore;
590+
use deno_runtime::deno_tls::rustls::RootCertStore;
591591

592592
use crate::version;
593593

ext/fetch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ deno_core.workspace = true
2020
deno_permissions.workspace = true
2121
deno_tls.workspace = true
2222
dyn-clone = "1"
23-
http_v02.workspace = true
23+
http.workspace = true
2424
reqwest.workspace = true
2525
serde.workspace = true
2626
serde_json.workspace = true

ext/fetch/fs_fetch_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl FetchHandler for FsFetchHandler {
3131
let file = tokio::fs::File::open(path).map_err(|_| ()).await?;
3232
let stream = ReaderStream::new(file);
3333
let body = reqwest::Body::wrap_stream(stream);
34-
let response = http_v02::Response::builder()
34+
let response = http::Response::builder()
3535
.status(StatusCode::OK)
3636
.body(body)
3737
.map_err(|_| ())?

ext/fetch/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ use data_url::DataUrl;
4747
use deno_tls::TlsKey;
4848
use deno_tls::TlsKeys;
4949
use deno_tls::TlsKeysHolder;
50-
use http_v02::header::CONTENT_LENGTH;
51-
use http_v02::Uri;
50+
use http::header::CONTENT_LENGTH;
51+
use http::Uri;
5252
use reqwest::header::HeaderMap;
5353
use reqwest::header::HeaderName;
5454
use reqwest::header::HeaderValue;
@@ -449,12 +449,9 @@ where
449449
.decode_to_vec()
450450
.map_err(|e| type_error(format!("{e:?}")))?;
451451

452-
let response = http_v02::Response::builder()
453-
.status(http_v02::StatusCode::OK)
454-
.header(
455-
http_v02::header::CONTENT_TYPE,
456-
data_url.mime_type().to_string(),
457-
)
452+
let response = http::Response::builder()
453+
.status(http::StatusCode::OK)
454+
.header(http::header::CONTENT_TYPE, data_url.mime_type().to_string())
458455
.body(reqwest::Body::from(body))?;
459456

460457
let fut = async move { Ok(Ok(Response::from(response))) };

ext/kv/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ path = "lib.rs"
1717
anyhow.workspace = true
1818
async-trait.workspace = true
1919
base64.workspace = true
20+
bytes.workspace = true
2021
chrono = { workspace = true, features = ["now"] }
2122
deno_core.workspace = true
2223
deno_fetch.workspace = true
@@ -27,6 +28,7 @@ denokv_proto.workspace = true
2728
denokv_remote.workspace = true
2829
denokv_sqlite.workspace = true
2930
faster-hex.workspace = true
31+
http.workspace = true
3032
log.workspace = true
3133
num-bigint.workspace = true
3234
prost.workspace = true

ext/kv/remote.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ use std::sync::Arc;
88
use crate::DatabaseHandler;
99
use anyhow::Context;
1010
use async_trait::async_trait;
11+
use bytes::Bytes;
1112
use deno_core::error::type_error;
1213
use deno_core::error::AnyError;
14+
use deno_core::futures::Stream;
15+
use deno_core::futures::TryStreamExt as _;
1316
use deno_core::OpState;
1417
use deno_fetch::create_http_client;
18+
use deno_fetch::reqwest;
1519
use deno_fetch::CreateHttpClientOptions;
1620
use deno_tls::rustls::RootCertStore;
1721
use deno_tls::Proxy;
1822
use deno_tls::RootCertStoreProvider;
1923
use deno_tls::TlsKeys;
2024
use denokv_remote::MetadataEndpoint;
2125
use denokv_remote::Remote;
26+
use denokv_remote::RemoteResponse;
27+
use denokv_remote::RemoteTransport;
2228
use url::Url;
2329

2430
#[derive(Clone)]
@@ -102,11 +108,44 @@ impl<P: RemoteDbHandlerPermissions + 'static> denokv_remote::RemotePermissions
102108
}
103109
}
104110

111+
#[derive(Clone)]
112+
pub struct ReqwestClient(reqwest::Client);
113+
pub struct ReqwestResponse(reqwest::Response);
114+
115+
impl RemoteTransport for ReqwestClient {
116+
type Response = ReqwestResponse;
117+
async fn post(
118+
&self,
119+
url: Url,
120+
headers: http::HeaderMap,
121+
body: Bytes,
122+
) -> Result<(Url, http::StatusCode, Self::Response), anyhow::Error> {
123+
let res = self.0.post(url).headers(headers).body(body).send().await?;
124+
let url = res.url().clone();
125+
let status = res.status();
126+
Ok((url, status, ReqwestResponse(res)))
127+
}
128+
}
129+
130+
impl RemoteResponse for ReqwestResponse {
131+
async fn bytes(self) -> Result<Bytes, anyhow::Error> {
132+
Ok(self.0.bytes().await?)
133+
}
134+
fn stream(
135+
self,
136+
) -> impl Stream<Item = Result<Bytes, anyhow::Error>> + Send + Sync {
137+
self.0.bytes_stream().map_err(|e| e.into())
138+
}
139+
async fn text(self) -> Result<String, anyhow::Error> {
140+
Ok(self.0.text().await?)
141+
}
142+
}
143+
105144
#[async_trait(?Send)]
106145
impl<P: RemoteDbHandlerPermissions + 'static> DatabaseHandler
107146
for RemoteDbHandler<P>
108147
{
109-
type DB = Remote<PermissionChecker<P>>;
148+
type DB = Remote<PermissionChecker<P>, ReqwestClient>;
110149

111150
async fn open(
112151
&self,
@@ -162,13 +201,14 @@ impl<P: RemoteDbHandlerPermissions + 'static> DatabaseHandler
162201
http2: true,
163202
},
164203
)?;
204+
let reqwest_client = ReqwestClient(client);
165205

166206
let permissions = PermissionChecker {
167207
state: state.clone(),
168208
_permissions: PhantomData,
169209
};
170210

171-
let remote = Remote::new(client, permissions, metadata_endpoint);
211+
let remote = Remote::new(reqwest_client, permissions, metadata_endpoint);
172212

173213
Ok(remote)
174214
}

ext/net/ops_tls.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ use deno_tls::create_client_config;
3131
use deno_tls::load_certs;
3232
use deno_tls::load_private_keys;
3333
use deno_tls::new_resolver;
34-
use deno_tls::rustls::Certificate;
34+
use deno_tls::rustls::pki_types::ServerName;
3535
use deno_tls::rustls::ClientConnection;
36-
use deno_tls::rustls::PrivateKey;
3736
use deno_tls::rustls::ServerConfig;
38-
use deno_tls::rustls::ServerName;
37+
use deno_tls::webpki::types::CertificateDer;
38+
use deno_tls::webpki::types::PrivateKeyDer;
3939
use deno_tls::ServerConfigProvider;
4040
use deno_tls::SocketUse;
4141
use deno_tls::TlsKey;
@@ -48,7 +48,6 @@ use serde::Deserialize;
4848
use std::borrow::Cow;
4949
use std::cell::RefCell;
5050
use std::convert::From;
51-
use std::convert::TryFrom;
5251
use std::fs::File;
5352
use std::io::BufReader;
5453
use std::io::ErrorKind;
@@ -294,14 +293,14 @@ where
294293
{
295294
let rid = args.rid;
296295
let hostname = match &*args.hostname {
297-
"" => "localhost",
298-
n => n,
296+
"" => "localhost".to_string(),
297+
n => n.to_string(),
299298
};
300299

301300
{
302301
let mut s = state.borrow_mut();
303302
let permissions = s.borrow_mut::<NP>();
304-
permissions.check_net(&(hostname, Some(0)), "Deno.startTls()")?;
303+
permissions.check_net(&(&hostname, Some(0)), "Deno.startTls()")?;
305304
}
306305

307306
let ca_certs = args
@@ -310,8 +309,8 @@ where
310309
.map(|s| s.into_bytes())
311310
.collect::<Vec<_>>();
312311

313-
let hostname_dns =
314-
ServerName::try_from(hostname).map_err(|_| invalid_hostname(hostname))?;
312+
let hostname_dns = ServerName::try_from(hostname.to_string())
313+
.map_err(|_| invalid_hostname(&hostname))?;
315314

316315
let unsafely_ignore_certificate_errors = state
317316
.borrow()
@@ -412,9 +411,9 @@ where
412411
.borrow::<DefaultTlsOptions>()
413412
.root_cert_store()?;
414413
let hostname_dns = if let Some(server_name) = args.server_name {
415-
ServerName::try_from(server_name.as_str())
414+
ServerName::try_from(server_name)
416415
} else {
417-
ServerName::try_from(&*addr.hostname)
416+
ServerName::try_from(addr.hostname.clone())
418417
}
419418
.map_err(|_| invalid_hostname(&addr.hostname))?;
420419
let connect_addr = resolve_addr(&addr.hostname, addr.port)
@@ -456,15 +455,17 @@ where
456455
Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr)))
457456
}
458457

459-
fn load_certs_from_file(path: &str) -> Result<Vec<Certificate>, AnyError> {
458+
fn load_certs_from_file(
459+
path: &str,
460+
) -> Result<Vec<CertificateDer<'static>>, AnyError> {
460461
let cert_file = File::open(path)?;
461462
let reader = &mut BufReader::new(cert_file);
462463
load_certs(reader)
463464
}
464465

465466
fn load_private_keys_from_file(
466467
path: &str,
467-
) -> Result<Vec<PrivateKey>, AnyError> {
468+
) -> Result<Vec<PrivateKeyDer<'static>>, AnyError> {
468469
let key_bytes = std::fs::read(path)?;
469470
load_private_keys(&key_bytes)
470471
}
@@ -513,7 +514,6 @@ where
513514
TlsKeys::Null => Err(anyhow!("Deno.listenTls requires a key")),
514515
TlsKeys::Static(TlsKey(cert, key)) => {
515516
let mut tls_config = ServerConfig::builder()
516-
.with_safe_defaults()
517517
.with_no_client_auth()
518518
.with_single_cert(cert, key)
519519
.map_err(|e| anyhow!(e))?;

ext/node/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ ecb.workspace = true
3838
elliptic-curve.workspace = true
3939
errno = "0.2.8"
4040
faster-hex.workspace = true
41-
h2 = { version = "0.3.26", features = ["unstable"] }
41+
h2.workspace = true
4242
hkdf.workspace = true
4343
home = "0.5.9"
44-
http_v02.workspace = true
44+
http.workspace = true
4545
idna = "0.3.0"
4646
indexmap.workspace = true
4747
ipnetwork = "0.20.0"

ext/node/ops/http2.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use deno_net::raw::NetworkStream;
2626
use h2;
2727
use h2::Reason;
2828
use h2::RecvStream;
29-
use http_v02;
30-
use http_v02::request::Parts;
31-
use http_v02::HeaderMap;
32-
use http_v02::Response;
33-
use http_v02::StatusCode;
29+
use http;
30+
use http::request::Parts;
31+
use http::HeaderMap;
32+
use http::Response;
33+
use http::StatusCode;
3434
use reqwest::header::HeaderName;
3535
use reqwest::header::HeaderValue;
3636
use url::Url;
@@ -311,7 +311,7 @@ pub async fn op_http2_client_request(
311311

312312
let url = url.join(&pseudo_path)?;
313313

314-
let mut req = http_v02::Request::builder()
314+
let mut req = http::Request::builder()
315315
.uri(url.as_str())
316316
.method(pseudo_method.as_str());
317317

@@ -383,7 +383,7 @@ pub async fn op_http2_client_send_trailers(
383383
.get::<Http2ClientStream>(stream_rid)?;
384384
let mut stream = RcRef::map(&resource, |r| &r.stream).borrow_mut().await;
385385

386-
let mut trailers_map = http_v02::HeaderMap::new();
386+
let mut trailers_map = http::HeaderMap::new();
387387
for (name, value) in trailers {
388388
trailers_map.insert(
389389
HeaderName::from_bytes(&name).unwrap(),

0 commit comments

Comments
 (0)