From 6805f0d2d4c93aba45659be51a6b79c621bf7f36 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 30 Nov 2021 07:40:44 -0500 Subject: [PATCH] cleanup --- ext/fetch/lib.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index dd42eed099..7acdc4a88c 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -63,6 +63,7 @@ pub struct Options { pub root_cert_store: Option, pub proxy: Option, pub request_builder_hook: Option RequestBuilder>, + /// Called on every request. Defaults to process-wide shared client. pub get_client: Option Client>, pub unsafely_ignore_certificate_errors: Option>, pub client_cert_chain_and_key: Option<(String, String)>, @@ -120,7 +121,7 @@ where } /// Assign to Options::get_client for a fetch that creates a new client for every request. -pub fn get_new_client(state: &mut OpState) -> Client { +pub fn new_client(state: &mut OpState) -> Client { let options = state.borrow::(); create_http_client( options.user_agent.clone(), @@ -133,20 +134,12 @@ pub fn get_new_client(state: &mut OpState) -> Client { .unwrap() } +/// Default behavior when Options::get_client is None. fn get_shared_client(state: &mut OpState) -> Client { if let Some(client) = state.try_borrow::() { client.clone() } else { - let options = state.borrow::(); - let client = create_http_client( - options.user_agent.clone(), - options.root_cert_store.clone(), - vec![], - options.proxy.clone(), - options.unsafely_ignore_certificate_errors.clone(), - options.client_cert_chain_and_key.clone(), - ) - .unwrap(); + let client = new_client(state); state.put::(client.clone()); client } @@ -234,8 +227,7 @@ where r.client.clone() } else { let options = state.borrow::(); - let client = options.get_client.unwrap()(state); - client + options.get_client.unwrap()(state) }; let method = Method::from_bytes(&args.method)?;