Skip to content

Commit

Permalink
fix(workers): Make importScripts() use the same HTTP client as `fet…
Browse files Browse the repository at this point in the history
…ch` (#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.
  • Loading branch information
Andreu Botella authored Oct 27, 2021
1 parent b44b26c commit 09dd77c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion runtime/ops/web_worker/sync_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -59,14 +61,16 @@ 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)
.map_err(|_| type_error("Invalid script URL"))?;

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();

Expand Down
4 changes: 1 addition & 3 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 09dd77c

Please sign in to comment.