diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-12-30 15:58:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-30 15:58:25 +0100 |
commit | 011d485ce5214a90aa64d557d8acdc0697c8ed49 (patch) | |
tree | c24ccbe22013cf27d97c4ebca9f7672d62a072e2 /cli/http_util.rs | |
parent | 46d76a7562025374600a7f866dfc68c1b7e268e9 (diff) |
use shared HTTP client (#3563)
This commit moves HTTP client to lazy_static. Effectively HTTP client is shared by whole Deno process and will reuse connections.
Diffstat (limited to 'cli/http_util.rs')
-rw-r--r-- | cli/http_util.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/cli/http_util.rs b/cli/http_util.rs index 1be9ad60f..83aaadd1e 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -14,20 +14,26 @@ use reqwest::Client; use std::future::Future; use url::Url; -/// Create new instance of async reqwest::Client. This client supports +lazy_static! { + static ref HTTP_CLIENT: Client = { + let mut headers = HeaderMap::new(); + headers.insert( + USER_AGENT, + format!("Deno/{}", version::DENO).parse().unwrap(), + ); + Client::builder() + .redirect(Policy::none()) + .default_headers(headers) + .use_rustls_tls() + .build() + .unwrap() + }; +} + +/// Get instance of async reqwest::Client. This client supports /// proxies and doesn't follow redirects. -pub fn get_client() -> Client { - let mut headers = HeaderMap::new(); - headers.insert( - USER_AGENT, - format!("Deno/{}", version::DENO).parse().unwrap(), - ); - Client::builder() - .redirect(Policy::none()) - .default_headers(headers) - .use_rustls_tls() - .build() - .unwrap() +pub fn get_client() -> &'static Client { + &HTTP_CLIENT } /// Construct the next uri based on base uri and location header fragment |