diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-16 16:10:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 16:10:01 +0100 |
commit | 1de02b0643bb21d89ce049943d2d2d27fb510ed0 (patch) | |
tree | 3b8c65b8bb5b0511452e8438f996fbe7dad41dfc /cli/file_fetcher.rs | |
parent | 91757f63fdc04f5844b58a8c0b76df601e84ac72 (diff) |
perf: share http client in file fetcher (#3683)
Diffstat (limited to 'cli/file_fetcher.rs')
-rw-r--r-- | cli/file_fetcher.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 471027e39..03b4a9d02 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -5,6 +5,7 @@ use crate::deno_error::ErrorKind; use crate::deno_error::GetErrorKind; use crate::disk_cache::DiskCache; use crate::http_util; +use crate::http_util::create_http_client; use crate::http_util::FetchOnceResult; use crate::msg; use crate::progress::Progress; @@ -12,6 +13,7 @@ use deno_core::ErrBox; use deno_core::ModuleSpecifier; use futures::future::Either; use futures::future::FutureExt; +use reqwest; use serde_json; use std; use std::collections::HashMap; @@ -75,6 +77,7 @@ pub struct SourceFileFetcher { use_disk_cache: bool, no_remote: bool, cached_only: bool, + http_client: reqwest::Client, } impl SourceFileFetcher { @@ -94,6 +97,7 @@ impl SourceFileFetcher { use_disk_cache, no_remote, cached_only, + http_client: create_http_client(), }; Ok(file_fetcher) @@ -395,10 +399,12 @@ impl SourceFileFetcher { let module_url = module_url.clone(); let headers = self.get_source_code_headers(&module_url); let module_etag = headers.etag; - + let http_client = self.http_client.clone(); // Single pass fetch, either yields code or yields redirect. let f = async move { - match http_util::fetch_string_once(&module_url, module_etag).await? { + match http_util::fetch_string_once(http_client, &module_url, module_etag) + .await? + { FetchOnceResult::NotModified => { let source_file = dir.fetch_cached_remote_source(&module_url)?.unwrap(); |