diff options
author | Andreu Botella <abb@randomunok.com> | 2021-10-27 06:09:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 15:09:58 +0200 |
commit | 09dd77c13edf59eb3748b5f21bd8b7141d822f61 (patch) | |
tree | ca7e61d2f77d8670901de7aa00871ca381401b12 /runtime/ops/web_worker/sync_fetch.rs | |
parent | b44b26c8842522e0e952c31aeb42c7fb85a5c7a7 (diff) |
fix(workers): Make `importScripts()` use the same HTTP client as `fetch` (#12540)
The initial implementation of `importScripts()` in #11338 used
`reqwest`'s default client to fetch HTTP scripts, which meant it would
not use certificates or other fetching configuration passed by command
line flags. This change fixes it.
Diffstat (limited to 'runtime/ops/web_worker/sync_fetch.rs')
-rw-r--r-- | runtime/ops/web_worker/sync_fetch.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index 0659241f1..fafe62047 100644 --- a/runtime/ops/web_worker/sync_fetch.rs +++ b/runtime/ops/web_worker/sync_fetch.rs @@ -38,6 +38,8 @@ pub fn op_worker_sync_fetch( let handle = state.borrow::<WebWorkerInternalHandle>().clone(); assert_eq!(handle.worker_type, WebWorkerType::Classic); + let client = state.borrow::<reqwest::Client>().clone(); + // TODO(andreubotella) It's not good to throw an exception related to blob // URLs when none of the script URLs use the blob scheme. // Also, in which contexts are blob URLs not supported? @@ -59,6 +61,7 @@ pub fn op_worker_sync_fetch( let handles: Vec<_> = scripts .into_iter() .map(|script| -> JoinHandle<Result<SyncFetchScript, AnyError>> { + let client = client.clone(); let blob_store = blob_store.clone(); runtime.spawn(async move { let script_url = Url::parse(&script) @@ -66,7 +69,8 @@ pub fn op_worker_sync_fetch( let (body, mime_type, res_url) = match script_url.scheme() { "http" | "https" => { - let resp = reqwest::get(script_url).await?.error_for_status()?; + let resp = + client.get(script_url).send().await?.error_for_status()?; let res_url = resp.url().to_string(); |