From b310f32e39785987ddd3491e189aad06381d0139 Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Thu, 16 Jan 2020 03:23:29 +0900 Subject: fix: process hangs when fetch called (#3657) Reverts 011d485 --- cli/http_util.rs | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'cli') diff --git a/cli/http_util.rs b/cli/http_util.rs index f9dc5933e..9dec1adb9 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -29,31 +29,20 @@ use std::task::Poll; use tokio::io::AsyncRead; use url::Url; -lazy_static! { - static ref HTTP_CLIENT: Client = { - let mut headers = HeaderMap::new(); - headers.insert( - USER_AGENT, - format!("Deno/{}", version::DENO).parse().unwrap(), - ); - // todo support brotli for fetch ops - headers.insert( - ACCEPT_ENCODING, HeaderValue::from_static("gzip") - ); - Client::builder() - .redirect(Policy::none()) - .default_headers(headers) - .use_rustls_tls() - .gzip(true) - .build() - .unwrap() - }; -} - -/// Get instance of async reqwest::Client. This client supports +/// Create new instance of async reqwest::Client. This client supports /// proxies and doesn't follow redirects. -pub fn get_client() -> &'static Client { - &HTTP_CLIENT as &Client +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() } /// Construct the next uri based on base uri and location header fragment @@ -101,7 +90,7 @@ pub fn fetch_string_once( cached_etag: Option, ) -> impl Future> { let url = url.clone(); - let client: &Client = get_client(); + let client = get_client(); let fut = async move { let mut request = client -- cgit v1.2.3