From 09dd77c13edf59eb3748b5f21bd8b7141d822f61 Mon Sep 17 00:00:00 2001 From: Andreu Botella Date: Wed, 27 Oct 2021 06:09:58 -0700 Subject: [PATCH] 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. --- runtime/ops/web_worker/sync_fetch.rs | 6 +++++- tools/wpt/expectation.json | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index 0659241f10..fafe620472 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::().clone(); assert_eq!(handle.worker_type, WebWorkerType::Classic); + let client = state.borrow::().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> { + 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(); diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json index 288d91bccd..6bcaf576ff 100644 --- a/tools/wpt/expectation.json +++ b/tools/wpt/expectation.json @@ -9070,9 +9070,7 @@ ], "catch.sub.any.worker.html": [ "Cross-origin syntax error", - "Cross-origin throw", - "Redirect-to-cross-origin syntax error", - "Redirect-to-Cross-origin throw" + "Cross-origin throw" ], "report-error-cross-origin.sub.any.worker.html": false, "report-error-redirect-to-cross-origin.sub.any.worker.html": false,