Skip to content

Commit 09dd77c

Browse files
author
Andreu Botella
authored
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.
1 parent b44b26c commit 09dd77c

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

runtime/ops/web_worker/sync_fetch.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub fn op_worker_sync_fetch(
3838
let handle = state.borrow::<WebWorkerInternalHandle>().clone();
3939
assert_eq!(handle.worker_type, WebWorkerType::Classic);
4040

41+
let client = state.borrow::<reqwest::Client>().clone();
42+
4143
// TODO(andreubotella) It's not good to throw an exception related to blob
4244
// URLs when none of the script URLs use the blob scheme.
4345
// Also, in which contexts are blob URLs not supported?
@@ -59,14 +61,16 @@ pub fn op_worker_sync_fetch(
5961
let handles: Vec<_> = scripts
6062
.into_iter()
6163
.map(|script| -> JoinHandle<Result<SyncFetchScript, AnyError>> {
64+
let client = client.clone();
6265
let blob_store = blob_store.clone();
6366
runtime.spawn(async move {
6467
let script_url = Url::parse(&script)
6568
.map_err(|_| type_error("Invalid script URL"))?;
6669

6770
let (body, mime_type, res_url) = match script_url.scheme() {
6871
"http" | "https" => {
69-
let resp = reqwest::get(script_url).await?.error_for_status()?;
72+
let resp =
73+
client.get(script_url).send().await?.error_for_status()?;
7074

7175
let res_url = resp.url().to_string();
7276

tools/wpt/expectation.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9070,9 +9070,7 @@
90709070
],
90719071
"catch.sub.any.worker.html": [
90729072
"Cross-origin syntax error",
9073-
"Cross-origin throw",
9074-
"Redirect-to-cross-origin syntax error",
9075-
"Redirect-to-Cross-origin throw"
9073+
"Cross-origin throw"
90769074
],
90779075
"report-error-cross-origin.sub.any.worker.html": false,
90789076
"report-error-redirect-to-cross-origin.sub.any.worker.html": false,

0 commit comments

Comments
 (0)