summaryrefslogtreecommitdiff
path: root/cli/ops/websocket.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-12-11 18:49:26 +0100
committerGitHub <noreply@github.com>2020-12-11 18:49:26 +0100
commit65e72b68acf57da8462b8e7b057e7adb9393b698 (patch)
tree00e955e1186b9512b009acbb6ee80feb8a3f1733 /cli/ops/websocket.rs
parent9414dee9e56a9f42c07ada4f8e1be864a1a1b936 (diff)
refactor(cli): decouple ops from ProgramState and Flags (#8659)
This commit does major refactor of "Worker" and "WebWorker", in order to decouple them from "ProgramState" and "Flags". The main points of interest are "create_main_worker()" and "create_web_worker_callback()" functions which are responsible for creating "Worker" and "WebWorker" in CLI context. As a result it is now possible to factor out common "runtime" functionality into a separate crate.
Diffstat (limited to 'cli/ops/websocket.rs')
-rw-r--r--cli/ops/websocket.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/cli/ops/websocket.rs b/cli/ops/websocket.rs
index c04c3b476..de6357c87 100644
--- a/cli/ops/websocket.rs
+++ b/cli/ops/websocket.rs
@@ -33,7 +33,17 @@ use tokio_tungstenite::tungstenite::{
use tokio_tungstenite::{client_async, WebSocketStream};
use webpki::DNSNameRef;
-pub fn init(rt: &mut deno_core::JsRuntime) {
+#[derive(Clone)]
+struct WsCaFile(String);
+
+pub fn init(rt: &mut deno_core::JsRuntime, maybe_ca_file: Option<&str>) {
+ {
+ let op_state = rt.op_state();
+ let mut state = op_state.borrow_mut();
+ if let Some(ca_file) = maybe_ca_file {
+ state.put::<WsCaFile>(WsCaFile(ca_file.to_string()));
+ }
+ }
super::reg_json_sync(rt, "op_ws_check_permission", op_ws_check_permission);
super::reg_json_async(rt, "op_ws_create", op_ws_create);
super::reg_json_async(rt, "op_ws_send", op_ws_send);
@@ -92,10 +102,7 @@ pub async fn op_ws_create(
);
}
- let ca_file = {
- let program_state = super::global_state2(&state);
- program_state.flags.ca_file.clone()
- };
+ let maybe_ca_file = state.borrow().try_borrow::<WsCaFile>().cloned();
let uri: Uri = args.url.parse()?;
let mut request = Request::builder().method(Method::GET).uri(&uri);
@@ -128,8 +135,8 @@ pub async fn op_ws_create(
.root_store
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
- if let Some(path) = ca_file {
- let key_file = File::open(path)?;
+ if let Some(ws_ca_file) = maybe_ca_file {
+ let key_file = File::open(ws_ca_file.0)?;
let reader = &mut BufReader::new(key_file);
config.root_store.add_pem_file(reader).unwrap();
}