summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-09-22 11:12:08 +0200
committerGitHub <noreply@github.com>2021-09-22 11:12:08 +0200
commit82cfb46bd1d64d41afda544bde9ef57096fb520b (patch)
tree5f978421fd242b739c36cf65f9d30705d9ca1bfa
parentf27902e749fb3a78ca35a0dc41c9fc53cd2806e1 (diff)
chore(ext/net): improve embedder friendliness (#12178)
Default to None if UnsafelyIgnoreCertificateErrors is not present in the OpState. Embedders may not have a need for restricting outgoing TLS connections and having them hunt through the source code for the magic incantation that makes the borrow panics go away, is less user friendly.
-rw-r--r--ext/net/ops_tls.rs10
-rw-r--r--ext/websocket/lib.rs5
2 files changed, 6 insertions, 9 deletions
diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs
index 89879da68..17367af54 100644
--- a/ext/net/ops_tls.rs
+++ b/ext/net/ops_tls.rs
@@ -699,9 +699,8 @@ where
let unsafely_ignore_certificate_errors = state
.borrow()
- .borrow::<UnsafelyIgnoreCertificateErrors>()
- .0
- .clone();
+ .try_borrow::<UnsafelyIgnoreCertificateErrors>()
+ .and_then(|it| it.0.clone());
// TODO(@justinmchase): Ideally the certificate store is created once
// and not cloned. The store should be wrapped in Arc<T> to reduce
@@ -768,9 +767,8 @@ where
let cert_file = args.cert_file.as_deref();
let unsafely_ignore_certificate_errors = state
.borrow()
- .borrow::<UnsafelyIgnoreCertificateErrors>()
- .0
- .clone();
+ .try_borrow::<UnsafelyIgnoreCertificateErrors>()
+ .and_then(|it| it.0.clone());
if args.cert_chain.is_some() {
super::check_unstable2(&state, "ConnectTlsOptions.certChain");
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs
index c75fa1742..f9f11e591 100644
--- a/ext/websocket/lib.rs
+++ b/ext/websocket/lib.rs
@@ -224,9 +224,8 @@ where
let unsafely_ignore_certificate_errors = state
.borrow()
- .borrow::<UnsafelyIgnoreCertificateErrors>()
- .0
- .clone();
+ .try_borrow::<UnsafelyIgnoreCertificateErrors>()
+ .and_then(|it| it.0.clone());
let root_cert_store = state.borrow().borrow::<WsRootStore>().0.clone();
let user_agent = state.borrow().borrow::<WsUserAgent>().0.clone();
let uri: Uri = args.url.parse()?;