1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

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.
This commit is contained in:
Andreu Botella 2021-10-27 06:09:58 -07:00 committed by GitHub
parent b44b26c884
commit 09dd77c13e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

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

View file

@ -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,