diff --git a/cli/ops/fetch.rs b/cli/ops/fetch.rs index 5a646325ed..869c7c5b88 100644 --- a/cli/ops/fetch.rs +++ b/cli/ops/fetch.rs @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use super::dispatch_json::{Deserialize, JsonOp, Value}; use super::io::{StreamResource, StreamResourceHolder}; -use crate::http_util::{create_http_client, HttpBody}; +use crate::http_util::HttpBody; use crate::op_error::OpError; use crate::state::State; use deno_core::CoreIsolate; @@ -33,8 +33,7 @@ pub fn op_fetch( let args: FetchArgs = serde_json::from_value(args)?; let url = args.url; - let client = - create_http_client(state.borrow().global_state.flags.ca_file.clone())?; + let client = &state.borrow().http_client; let method = match args.method { Some(method_str) => Method::from_bytes(method_str.as_bytes()) diff --git a/cli/state.rs b/cli/state.rs index aa78f5c1ae..f04b577b42 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -2,6 +2,7 @@ use crate::file_fetcher::SourceFileFetcher; use crate::global_state::GlobalState; use crate::global_timer::GlobalTimer; +use crate::http_util::create_http_client; use crate::import_map::ImportMap; use crate::metrics::Metrics; use crate::op_error::OpError; @@ -61,6 +62,7 @@ pub struct StateInner { pub target_lib: TargetLib, pub is_main: bool, pub is_internal: bool, + pub http_client: reqwest::Client, } impl State { @@ -338,6 +340,8 @@ impl State { global_state.permissions.clone() }; + let http_client = create_http_client(global_state.flags.ca_file.clone())?; + let state = Rc::new(RefCell::new(StateInner { global_state, main_module, @@ -352,6 +356,7 @@ impl State { target_lib: TargetLib::Main, is_main: true, is_internal, + http_client, })); Ok(Self(state)) @@ -374,6 +379,8 @@ impl State { global_state.permissions.clone() }; + let http_client = create_http_client(global_state.flags.ca_file.clone())?; + let state = Rc::new(RefCell::new(StateInner { global_state, main_module, @@ -388,6 +395,7 @@ impl State { target_lib: TargetLib::Worker, is_main: false, is_internal: false, + http_client, })); Ok(Self(state))