mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
Share reqwest client between fetch calls (#6792)
This commit is contained in:
parent
da48fa42d3
commit
071a6e284a
2 changed files with 10 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
||||||
use super::io::{StreamResource, StreamResourceHolder};
|
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::op_error::OpError;
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use deno_core::CoreIsolate;
|
use deno_core::CoreIsolate;
|
||||||
|
@ -33,8 +33,7 @@ pub fn op_fetch(
|
||||||
let args: FetchArgs = serde_json::from_value(args)?;
|
let args: FetchArgs = serde_json::from_value(args)?;
|
||||||
let url = args.url;
|
let url = args.url;
|
||||||
|
|
||||||
let client =
|
let client = &state.borrow().http_client;
|
||||||
create_http_client(state.borrow().global_state.flags.ca_file.clone())?;
|
|
||||||
|
|
||||||
let method = match args.method {
|
let method = match args.method {
|
||||||
Some(method_str) => Method::from_bytes(method_str.as_bytes())
|
Some(method_str) => Method::from_bytes(method_str.as_bytes())
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
use crate::file_fetcher::SourceFileFetcher;
|
use crate::file_fetcher::SourceFileFetcher;
|
||||||
use crate::global_state::GlobalState;
|
use crate::global_state::GlobalState;
|
||||||
use crate::global_timer::GlobalTimer;
|
use crate::global_timer::GlobalTimer;
|
||||||
|
use crate::http_util::create_http_client;
|
||||||
use crate::import_map::ImportMap;
|
use crate::import_map::ImportMap;
|
||||||
use crate::metrics::Metrics;
|
use crate::metrics::Metrics;
|
||||||
use crate::op_error::OpError;
|
use crate::op_error::OpError;
|
||||||
|
@ -61,6 +62,7 @@ pub struct StateInner {
|
||||||
pub target_lib: TargetLib,
|
pub target_lib: TargetLib,
|
||||||
pub is_main: bool,
|
pub is_main: bool,
|
||||||
pub is_internal: bool,
|
pub is_internal: bool,
|
||||||
|
pub http_client: reqwest::Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
@ -338,6 +340,8 @@ impl State {
|
||||||
global_state.permissions.clone()
|
global_state.permissions.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let http_client = create_http_client(global_state.flags.ca_file.clone())?;
|
||||||
|
|
||||||
let state = Rc::new(RefCell::new(StateInner {
|
let state = Rc::new(RefCell::new(StateInner {
|
||||||
global_state,
|
global_state,
|
||||||
main_module,
|
main_module,
|
||||||
|
@ -352,6 +356,7 @@ impl State {
|
||||||
target_lib: TargetLib::Main,
|
target_lib: TargetLib::Main,
|
||||||
is_main: true,
|
is_main: true,
|
||||||
is_internal,
|
is_internal,
|
||||||
|
http_client,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Self(state))
|
Ok(Self(state))
|
||||||
|
@ -374,6 +379,8 @@ impl State {
|
||||||
global_state.permissions.clone()
|
global_state.permissions.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let http_client = create_http_client(global_state.flags.ca_file.clone())?;
|
||||||
|
|
||||||
let state = Rc::new(RefCell::new(StateInner {
|
let state = Rc::new(RefCell::new(StateInner {
|
||||||
global_state,
|
global_state,
|
||||||
main_module,
|
main_module,
|
||||||
|
@ -388,6 +395,7 @@ impl State {
|
||||||
target_lib: TargetLib::Worker,
|
target_lib: TargetLib::Worker,
|
||||||
is_main: false,
|
is_main: false,
|
||||||
is_internal: false,
|
is_internal: false,
|
||||||
|
http_client,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(Self(state))
|
Ok(Self(state))
|
||||||
|
|
Loading…
Reference in a new issue