summaryrefslogtreecommitdiff
path: root/cli/file_fetcher.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-01 16:42:05 -0400
committerGitHub <noreply@github.com>2023-05-01 16:42:05 -0400
commit913176313b6869eeb29b8d48e0c8d80227fa6544 (patch)
treecc0128b36ea9b22207a3dd41a401ae4ecd131e74 /cli/file_fetcher.rs
parentecc70eb58fd5531f3b93402cf781e93ef2bb4d64 (diff)
perf: lazily create RootCertStore (#18938)
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r--cli/file_fetcher.rs39
1 files changed, 24 insertions, 15 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 38b96c72d..fd8c0f793 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -178,7 +178,7 @@ pub struct FileFetcher {
cache: FileCache,
cache_setting: CacheSetting,
pub http_cache: HttpCache,
- http_client: HttpClient,
+ http_client: Arc<HttpClient>,
blob_store: BlobStore,
download_log_level: log::Level,
progress_bar: Option<ProgressBar>,
@@ -189,7 +189,7 @@ impl FileFetcher {
http_cache: HttpCache,
cache_setting: CacheSetting,
allow_remote: bool,
- http_client: HttpClient,
+ http_client: Arc<HttpClient>,
blob_store: BlobStore,
progress_bar: Option<ProgressBar>,
) -> Self {
@@ -660,7 +660,7 @@ async fn fetch_once<'a>(
http_client: &HttpClient,
args: FetchOnceArgs<'a>,
) -> Result<FetchOnceResult, AnyError> {
- let mut request = http_client.get_no_redirect(args.url.clone());
+ let mut request = http_client.get_no_redirect(args.url.clone())?;
if let Some(etag) = args.maybe_etag {
let if_none_match_val = HeaderValue::from_str(&etag)?;
@@ -769,7 +769,7 @@ mod tests {
HttpCache::new(&location),
cache_setting,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
blob_store.clone(),
None,
);
@@ -1207,7 +1207,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::ReloadAll,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1232,7 +1232,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1257,7 +1257,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1398,7 +1398,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1426,7 +1426,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1525,7 +1525,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
false,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1550,7 +1550,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Only,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -1558,7 +1558,7 @@ mod tests {
HttpCache::new(&location),
CacheSetting::Use,
true,
- HttpClient::new(None, None).unwrap(),
+ Arc::new(HttpClient::new(None, None)),
BlobStore::default(),
None,
);
@@ -2021,15 +2021,24 @@ mod tests {
#[ignore] // https://github.com/denoland/deno/issues/12561
async fn test_fetch_with_empty_certificate_store() {
use deno_runtime::deno_tls::rustls::RootCertStore;
+ use deno_runtime::deno_tls::RootCertStoreProvider;
+
+ struct ValueRootCertStoreProvider(RootCertStore);
+
+ impl RootCertStoreProvider for ValueRootCertStoreProvider {
+ fn get_or_try_init(&self) -> Result<&RootCertStore, AnyError> {
+ Ok(&self.0)
+ }
+ }
let _http_server_guard = test_util::http_server();
// Relies on external http server with a valid mozilla root CA cert.
let url = Url::parse("https://deno.land").unwrap();
let client = HttpClient::new(
- Some(RootCertStore::empty()), // no certs loaded at all
+ // no certs loaded at all
+ Some(Arc::new(ValueRootCertStoreProvider(RootCertStore::empty()))),
None,
- )
- .unwrap();
+ );
let result = fetch_once(
&client,