diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2024-07-13 17:08:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-13 21:08:23 +0000 |
commit | e0cfc9da39e1d05e6a95c89c41cff8ae34fcbd66 (patch) | |
tree | 97e291e29e8e0e49796f3929e9bf5f42d0e5f76c /runtime | |
parent | f6fd6619e708a515831f707438368d81b0c9aa56 (diff) |
Revert "refactor(fetch): reimplement fetch with hyper instead of reqwest (#24237)" (#24574)
This reverts commit f6fd6619e708a515831f707438368d81b0c9aa56.
I'm seeing a difference between canary and 1.45.2. In
`deno-docs/reference_gen` I can't download dax when running `deno task
types`
```
~/src/deno-docs/reference_gen# deno upgrade --canary
Looking up latest canary version
Found latest version f6fd6619e708a515831f707438368d81b0c9aa56
Downloading https://dl.deno.land/canary/f6fd6619e708a515831f707438368d81b0c9aa56/deno-aarch64-apple-darwin.zip
Deno is upgrading to version f6fd6619e708a515831f707438368d81b0c9aa56
Archive: /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmpb5lDnq/deno.zip
inflating: deno
Upgraded successfully
~/src/deno-docs/reference_gen# deno -v
deno 1.45.2+f6fd661
~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno
~/src/deno-docs/reference_gen# deno task types
Task types deno task types:deno && deno task types:node
Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts
error: JSR package manifest for '@david/dax' failed to load. expected value at line 1 column 1
at file:///Users/ry/src/deno-docs/reference_gen/deno-docs.ts:2:15
~/src/deno-docs/reference_gen# deno upgrade --version 1.45.2
Downloading https://github.com/denoland/deno/releases/download/v1.45.2/deno-aarch64-apple-darwin.zip
Deno is upgrading to version 1.45.2
Archive: /var/folders/9v/kys6gqns6kl8nksyn4l1f9v40000gn/T/.tmp3R7uhF/deno.zip
inflating: deno
Upgraded successfully
~/src/deno-docs/reference_gen# rm -rf /Users/ry/Library/Caches/deno
~/src/deno-docs/reference_gen# deno task types
Task types deno task types:deno && deno task types:node
Task types:deno deno run --allow-read --allow-write --allow-run --allow-env --allow-sys deno-docs.ts
Task types:node deno run --allow-read --allow-write=. --allow-env --allow-sys node-docs.ts
```
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/errors.rs | 47 | ||||
-rw-r--r-- | runtime/ops/web_worker/sync_fetch.rs | 26 |
2 files changed, 35 insertions, 38 deletions
diff --git a/runtime/errors.rs b/runtime/errors.rs index 694402773..7f2e49250 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -13,6 +13,7 @@ use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::url; use deno_core::ModuleResolutionError; +use deno_fetch::reqwest; use std::env; use std::error::Error; use std::io; @@ -100,6 +101,27 @@ fn get_regex_error_class(error: ®ex::Error) -> &'static str { } } +fn get_request_error_class(error: &reqwest::Error) -> &'static str { + error + .source() + .and_then(|inner_err| { + (inner_err + .downcast_ref::<io::Error>() + .map(get_io_error_class)) + .or_else(|| { + inner_err + .downcast_ref::<serde_json::error::Error>() + .map(get_serde_json_error_class) + }) + .or_else(|| { + inner_err + .downcast_ref::<url::ParseError>() + .map(get_url_parse_error_class) + }) + }) + .unwrap_or("Http") +} + fn get_serde_json_error_class( error: &serde_json::error::Error, ) -> &'static str { @@ -120,17 +142,7 @@ fn get_url_parse_error_class(_error: &url::ParseError) -> &'static str { "URIError" } -fn get_hyper_error_class(_error: &hyper::Error) -> &'static str { - "Http" -} - -fn get_hyper_util_error_class( - _error: &hyper_util::client::legacy::Error, -) -> &'static str { - "Http" -} - -fn get_hyper_v014_error_class(_error: &hyper_v014::Error) -> &'static str { +fn get_hyper_error_class(_error: &hyper_v014::Error) -> &'static str { "Http" } @@ -163,18 +175,13 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> { e.downcast_ref::<dlopen2::Error>() .map(get_dlopen_error_class) }) - .or_else(|| e.downcast_ref::<hyper::Error>().map(get_hyper_error_class)) - .or_else(|| { - e.downcast_ref::<hyper_util::client::legacy::Error>() - .map(get_hyper_util_error_class) - }) .or_else(|| { e.downcast_ref::<hyper_v014::Error>() - .map(get_hyper_v014_error_class) + .map(get_hyper_error_class) }) .or_else(|| { e.downcast_ref::<Arc<hyper_v014::Error>>() - .map(|e| get_hyper_v014_error_class(e)) + .map(|e| get_hyper_error_class(e)) }) .or_else(|| { e.downcast_ref::<deno_core::Canceled>().map(|e| { @@ -195,6 +202,10 @@ pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> { e.downcast_ref::<notify::Error>() .map(get_notify_error_class) }) + .or_else(|| { + e.downcast_ref::<reqwest::Error>() + .map(get_request_error_class) + }) .or_else(|| e.downcast_ref::<regex::Error>().map(get_regex_error_class)) .or_else(|| { e.downcast_ref::<serde_json::error::Error>() diff --git a/runtime/ops/web_worker/sync_fetch.rs b/runtime/ops/web_worker/sync_fetch.rs index cdb151a86..37286ca62 100644 --- a/runtime/ops/web_worker/sync_fetch.rs +++ b/runtime/ops/web_worker/sync_fetch.rs @@ -13,7 +13,6 @@ use deno_core::OpState; use deno_fetch::data_url::DataUrl; use deno_web::BlobStore; use deno_websocket::DomExceptionNetworkError; -use http_body_util::BodyExt; use hyper::body::Bytes; use serde::Deserialize; use serde::Serialize; @@ -79,23 +78,10 @@ pub fn op_worker_sync_fetch( let (body, mime_type, res_url) = match script_url.scheme() { "http" | "https" => { - let mut req = http::Request::new( - http_body_util::Empty::new() - .map_err(|never| match never {}) - .boxed(), - ); - *req.uri_mut() = script_url.as_str().parse()?; - - let resp = client.send(req).await?; - - if resp.status().is_client_error() - || resp.status().is_server_error() - { - return Err(type_error(format!( - "http status error: {}", - resp.status() - ))); - } + let resp = + client.get(script_url).send().await?.error_for_status()?; + + let res_url = resp.url().to_string(); // TODO(andreubotella) Properly run fetch's "extract a MIME type". let mime_type = resp @@ -107,9 +93,9 @@ pub fn op_worker_sync_fetch( // Always check the MIME type with HTTP(S). loose_mime_checks = false; - let body = resp.collect().await?.to_bytes(); + let body = resp.bytes().await?; - (body, mime_type, script) + (body, mime_type, res_url) } "data" => { let data_url = DataUrl::process(&script) |