mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
Remove http_client from CliState, store in OpState directly (#7497)
This commit is contained in:
parent
b2fa903d64
commit
0715803b7f
3 changed files with 11 additions and 12 deletions
|
@ -51,9 +51,9 @@ async fn op_fetch(
|
||||||
.ok_or_else(bad_resource_id)?;
|
.ok_or_else(bad_resource_id)?;
|
||||||
r.client.clone()
|
r.client.clone()
|
||||||
} else {
|
} else {
|
||||||
let cli_state = super::cli_state2(&state);
|
let state_ = state.borrow();
|
||||||
let client_ref = cli_state.http_client.borrow();
|
let client = state_.borrow::<reqwest::Client>();
|
||||||
client_ref.clone()
|
client.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let method = match args.method {
|
let method = match args.method {
|
||||||
|
@ -103,14 +103,12 @@ async fn op_fetch(
|
||||||
))),
|
))),
|
||||||
);
|
);
|
||||||
|
|
||||||
let json_res = json!({
|
Ok(json!({
|
||||||
"bodyRid": rid,
|
"bodyRid": rid,
|
||||||
"status": status.as_u16(),
|
"status": status.as_u16(),
|
||||||
"statusText": status.canonical_reason().unwrap_or(""),
|
"statusText": status.canonical_reason().unwrap_or(""),
|
||||||
"headers": res_headers
|
"headers": res_headers
|
||||||
});
|
}))
|
||||||
|
|
||||||
Ok(json_res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HttpClientResource {
|
struct HttpClientResource {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
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::permissions::Permissions;
|
use crate::permissions::Permissions;
|
||||||
|
@ -48,7 +47,6 @@ pub struct CliState {
|
||||||
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: RefCell<reqwest::Client>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit_unstable(api_name: &str) {
|
pub fn exit_unstable(api_name: &str) {
|
||||||
|
@ -180,7 +178,6 @@ impl CliState {
|
||||||
target_lib: TargetLib::Main,
|
target_lib: TargetLib::Main,
|
||||||
is_main: true,
|
is_main: true,
|
||||||
is_internal,
|
is_internal,
|
||||||
http_client: create_http_client(fl.ca_file.as_deref())?.into(),
|
|
||||||
};
|
};
|
||||||
Ok(Rc::new(state))
|
Ok(Rc::new(state))
|
||||||
}
|
}
|
||||||
|
@ -208,7 +205,6 @@ impl CliState {
|
||||||
target_lib: TargetLib::Worker,
|
target_lib: TargetLib::Worker,
|
||||||
is_main: false,
|
is_main: false,
|
||||||
is_internal: false,
|
is_internal: false,
|
||||||
http_client: create_http_client(fl.ca_file.as_deref())?.into(),
|
|
||||||
};
|
};
|
||||||
Ok(Rc::new(state))
|
Ok(Rc::new(state))
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,12 +107,13 @@ impl Worker {
|
||||||
state: &Rc<CliState>,
|
state: &Rc<CliState>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let global_state = state.global_state.clone();
|
let global_state = state.global_state.clone();
|
||||||
|
let global_state_ = global_state.clone();
|
||||||
|
|
||||||
let mut isolate = JsRuntime::new(RuntimeOptions {
|
let mut isolate = JsRuntime::new(RuntimeOptions {
|
||||||
module_loader: Some(state.clone()),
|
module_loader: Some(state.clone()),
|
||||||
startup_snapshot,
|
startup_snapshot,
|
||||||
js_error_create_fn: Some(Box::new(move |core_js_error| {
|
js_error_create_fn: Some(Box::new(move |core_js_error| {
|
||||||
JsError::create(core_js_error, &global_state.ts_compiler)
|
JsError::create(core_js_error, &global_state_.ts_compiler)
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
@ -121,6 +122,10 @@ impl Worker {
|
||||||
let mut op_state = op_state.borrow_mut();
|
let mut op_state = op_state.borrow_mut();
|
||||||
op_state.get_error_class_fn = &crate::errors::get_error_class_name;
|
op_state.get_error_class_fn = &crate::errors::get_error_class_name;
|
||||||
op_state.put(state.clone());
|
op_state.put(state.clone());
|
||||||
|
|
||||||
|
let ca_file = global_state.flags.ca_file.as_deref();
|
||||||
|
let client = crate::http_util::create_http_client(ca_file).unwrap();
|
||||||
|
op_state.put(client);
|
||||||
}
|
}
|
||||||
let inspector = {
|
let inspector = {
|
||||||
let global_state = &state.global_state;
|
let global_state = &state.global_state;
|
||||||
|
|
Loading…
Reference in a new issue