From f3b74350da69cb8cc0aedb1c1570abe2c64741ba Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 29 Nov 2021 10:29:41 -0500 Subject: [PATCH] refactor: remove deno_fetch::HttpClientDefaults (#12931) More clean up that should have been in cc83ad3 --- ext/fetch/lib.rs | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 3d4c51f8ff..ec2bc5e4e1 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -57,6 +57,7 @@ pub use reqwest; pub use fs_fetch_handler::FsFetchHandler; +#[derive(Clone)] pub struct Options { pub user_agent: String, pub root_cert_store: Option, @@ -67,8 +68,6 @@ pub struct Options { pub file_fetch_handler: Box, } -struct BoxFetchHandler(Box); - impl Default for Options { fn default() -> Self { Self { @@ -108,6 +107,7 @@ where ), ]) .state(move |state| { + state.put::(options.clone()); state.put::({ create_http_client( options.user_agent.clone(), @@ -119,33 +119,11 @@ where ) .unwrap() }); - state.put::(HttpClientDefaults { - user_agent: options.user_agent.clone(), - root_cert_store: options.root_cert_store.clone(), - proxy: options.proxy.clone(), - request_builder_hook: options.request_builder_hook, - unsafely_ignore_certificate_errors: options - .unsafely_ignore_certificate_errors - .clone(), - client_cert_chain_and_key: options.client_cert_chain_and_key.clone(), - }); - state.put(BoxFetchHandler(dyn_clone::clone_box( - &*options.file_fetch_handler, - ))); Ok(()) }) .build() } -pub struct HttpClientDefaults { - pub user_agent: String, - pub root_cert_store: Option, - pub proxy: Option, - pub request_builder_hook: Option RequestBuilder>, - pub unsafely_ignore_certificate_errors: Option>, - pub client_cert_chain_and_key: Option<(String, String)>, -} - pub type CancelableResponseFuture = Pin>>; @@ -251,8 +229,9 @@ where ))); } - let BoxFetchHandler(file_fetch_handler) = - state.borrow_mut::(); + let Options { + file_fetch_handler, .. + } = state.borrow_mut::(); let (request, maybe_request_body, maybe_cancel_handle) = file_fetch_handler.fetch_file(url); let request_rid = state.resource_table.add(FetchRequestResource(request)); @@ -317,8 +296,8 @@ where } } - let defaults = state.borrow::(); - if let Some(request_builder_hook) = defaults.request_builder_hook { + let options = state.borrow::(); + if let Some(request_builder_hook) = options.request_builder_hook { request = request_builder_hook(request); } @@ -575,7 +554,7 @@ where } }; - let defaults = state.borrow::(); + let options = state.borrow::(); let ca_certs = args .ca_certs .into_iter() @@ -583,11 +562,11 @@ where .collect::>(); let client = create_http_client( - defaults.user_agent.clone(), - defaults.root_cert_store.clone(), + options.user_agent.clone(), + options.root_cert_store.clone(), ca_certs, args.proxy, - defaults.unsafely_ignore_certificate_errors.clone(), + options.unsafely_ignore_certificate_errors.clone(), client_cert_chain_and_key, )?;