diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-11-18 17:28:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 17:28:14 -0500 |
commit | 763d492ed69c3a22310dd5c758995fbbbf3e06b8 (patch) | |
tree | da78f6e3ed7cc38924a73c2118b5824bcdb60e69 /cli/lsp/registries.rs | |
parent | 6962808f4b6bfa18312820f710bc57c17980531d (diff) |
fix(npm): use an http client with connection pool (#16705)
Should make downloading npm packages faster and more reliable.
Diffstat (limited to 'cli/lsp/registries.rs')
-rw-r--r-- | cli/lsp/registries.rs | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 3da435666..6fd48d8b9 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -13,10 +13,10 @@ use super::path_to_regex::StringOrVec; use super::path_to_regex::Token; use crate::deno_dir; -use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::CacheSetting; use crate::file_fetcher::FileFetcher; use crate::http_cache::HttpCache; +use crate::http_util::HttpClient; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; @@ -36,7 +36,6 @@ use once_cell::sync::Lazy; use regex::Regex; use std::collections::HashMap; use std::path::Path; -use std::path::PathBuf; use tower_lsp::lsp_types as lsp; const CONFIG_PATH: &str = "/.well-known/deno-import-intellisense.json"; @@ -409,14 +408,6 @@ enum VariableItems { List(VariableItemsList), } -#[derive(Debug, Default)] -pub struct ModuleRegistryOptions { - pub maybe_root_path: Option<PathBuf>, - pub maybe_ca_stores: Option<Vec<String>>, - pub maybe_ca_file: Option<String>, - pub unsafely_ignore_certificate_errors: Option<Vec<String>>, -} - /// A structure which holds the information about currently configured module /// registries and can provide completion information for URLs that match /// one of the enabled registries. @@ -433,28 +424,23 @@ impl Default for ModuleRegistry { // custom root. let dir = deno_dir::DenoDir::new(None).unwrap(); let location = dir.root.join("registries"); - Self::new(&location, ModuleRegistryOptions::default()).unwrap() + let http_client = HttpClient::new(None, None).unwrap(); + Self::new(&location, http_client).unwrap() } } impl ModuleRegistry { pub fn new( location: &Path, - options: ModuleRegistryOptions, + http_client: HttpClient, ) -> Result<Self, AnyError> { let http_cache = HttpCache::new(location); - let root_cert_store = Some(get_root_cert_store( - options.maybe_root_path, - options.maybe_ca_stores, - options.maybe_ca_file, - )?); let mut file_fetcher = FileFetcher::new( http_cache, CacheSetting::RespectHeaders, true, - root_cert_store, + http_client, BlobStore::default(), - options.unsafely_ignore_certificate_errors, None, )?; file_fetcher.set_download_log_level(super::logging::lsp_log_level()); @@ -1262,7 +1248,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); module_registry .enable("http://localhost:4545/") .await @@ -1323,7 +1310,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); module_registry .enable("http://localhost:4545/") .await @@ -1546,7 +1534,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); module_registry .enable_custom("http://localhost:4545/lsp/registries/deno-import-intellisense-key-first.json") .await @@ -1616,7 +1605,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let mut module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); module_registry .enable_custom("http://localhost:4545/lsp/registries/deno-import-intellisense-complex.json") .await @@ -1667,7 +1657,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); let result = module_registry.check_origin("http://localhost:4545").await; assert!(result.is_ok()); } @@ -1678,7 +1669,8 @@ mod tests { let temp_dir = TempDir::new(); let location = temp_dir.path().join("registries"); let module_registry = - ModuleRegistry::new(&location, ModuleRegistryOptions::default()).unwrap(); + ModuleRegistry::new(&location, HttpClient::new(None, None).unwrap()) + .unwrap(); let result = module_registry.check_origin("https://deno.com").await; assert!(result.is_err()); let err = result.unwrap_err().to_string(); |