1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

Share reqwest client between fetch calls (#6792)

This commit is contained in:
Luca Casonato 2020-07-18 21:05:08 +02:00 committed by GitHub
parent da48fa42d3
commit 071a6e284a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -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())

View file

@ -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))