perf: lazily create RootCertStore (#18938)

This commit is contained in:
David Sherret 2023-05-01 16:42:05 -04:00 committed by GitHub
parent ecc70eb58f
commit 913176313b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 344 additions and 173 deletions

View file

@ -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,