Skip to content

Commit 06a06ec

Browse files
committed
refactor: merge deno_fetch into deno_web
1 parent 3c0f289 commit 06a06ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1801
-1919
lines changed

Cargo.lock

Lines changed: 33 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ members = [
1313
"ext/canvas",
1414
"ext/cron",
1515
"ext/crypto",
16-
"ext/fetch",
1716
"ext/ffi",
1817
"ext/fs",
1918
"ext/http",
@@ -91,7 +90,6 @@ deno_cache = { version = "0.153.0", path = "./ext/cache" }
9190
deno_canvas = { version = "0.90.0", path = "./ext/canvas" }
9291
deno_cron = { version = "0.101.0", path = "./ext/cron" }
9392
deno_crypto = { version = "0.235.0", path = "./ext/crypto" }
94-
deno_fetch = { version = "0.245.0", path = "./ext/fetch" }
9593
deno_ffi = { version = "0.208.0", path = "./ext/ffi" }
9694
deno_fs = { version = "0.131.0", path = "./ext/fs" }
9795
deno_http = { version = "0.219.0", path = "./ext/http" }
@@ -442,8 +440,6 @@ opt-level = 3
442440
opt-level = 3
443441
[profile.release.package.deno_crypto]
444442
opt-level = 3
445-
[profile.release.package.deno_fetch]
446-
opt-level = 3
447443
[profile.release.package.deno_ffi]
448444
opt-level = 3
449445
[profile.release.package.deno_http]

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ deno_task_shell.workspace = true
9393
deno_telemetry.workspace = true
9494
deno_terminal.workspace = true
9595
deno_typescript_go_client_rust.workspace = true
96+
deno_web.workspace = true
9697
eszip.workspace = true
9798
libsui.workspace = true
9899
node_resolver = { workspace = true, features = ["graph", "sync"] }

cli/http_util.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ use deno_core::url::Url;
1515
use deno_error::JsError;
1616
use deno_error::JsErrorBox;
1717
use deno_lib::version::DENO_VERSION_INFO;
18-
use deno_runtime::deno_fetch;
19-
use deno_runtime::deno_fetch::CreateHttpClientOptions;
20-
use deno_runtime::deno_fetch::ResBody;
21-
use deno_runtime::deno_fetch::create_http_client;
2218
use deno_runtime::deno_tls::RootCertStoreProvider;
19+
use deno_web::fetch::CreateHttpClientOptions;
20+
use deno_web::fetch::ResBody;
21+
use deno_web::fetch::create_http_client;
2322
use http::HeaderMap;
2423
use http::StatusCode;
2524
use http::header::CONTENT_LENGTH;
@@ -33,7 +32,7 @@ use crate::util::progress_bar::UpdateGuard;
3332
#[derive(Debug, Error)]
3433
pub enum SendError {
3534
#[error(transparent)]
36-
Send(#[from] deno_fetch::ClientSendError),
35+
Send(#[from] deno_web::fetch::ClientSendError),
3736
#[error(transparent)]
3837
InvalidUri(#[from] http::uri::InvalidUri),
3938
}
@@ -44,7 +43,7 @@ pub struct HttpClientProvider {
4443
// it's not safe to share a reqwest::Client across tokio runtimes,
4544
// so we store these Clients keyed by thread id
4645
// https://github.com/seanmonstar/reqwest/issues/1148#issuecomment-910868788
47-
clients_by_thread_id: Mutex<HashMap<ThreadId, deno_fetch::Client>>,
46+
clients_by_thread_id: Mutex<HashMap<ThreadId, deno_web::fetch::Client>>,
4847
}
4948

5049
impl std::fmt::Debug for HttpClientProvider {
@@ -111,7 +110,7 @@ pub struct DownloadError(pub Box<DownloadErrorKind>);
111110
pub enum DownloadErrorKind {
112111
#[class(inherit)]
113112
#[error(transparent)]
114-
Fetch(deno_fetch::ClientSendError),
113+
Fetch(deno_web::fetch::ClientSendError),
115114
#[class(inherit)]
116115
#[error(transparent)]
117116
UrlParse(#[from] deno_core::url::ParseError),
@@ -178,7 +177,7 @@ impl HttpClientResponse {
178177

179178
#[derive(Debug)]
180179
pub struct HttpClient {
181-
client: deno_fetch::Client,
180+
client: deno_web::fetch::Client,
182181
// don't allow sending this across threads because then
183182
// it might be shared accidentally across tokio runtimes
184183
// which will cause issues
@@ -189,15 +188,15 @@ pub struct HttpClient {
189188
impl HttpClient {
190189
// DO NOT make this public. You should always be creating one of these from
191190
// the HttpClientProvider
192-
fn new(client: deno_fetch::Client) -> Self {
191+
fn new(client: deno_web::fetch::Client) -> Self {
193192
Self {
194193
client,
195194
_unsend_marker: deno_core::unsync::UnsendMarker::default(),
196195
}
197196
}
198197

199198
pub fn get(&self, url: Url) -> Result<RequestBuilder, http::Error> {
200-
let body = deno_fetch::ReqBody::empty();
199+
let body = deno_web::fetch::ReqBody::empty();
201200
let mut req = http::Request::new(body);
202201
*req.uri_mut() = url.as_str().parse()?;
203202
Ok(RequestBuilder {
@@ -209,7 +208,7 @@ impl HttpClient {
209208
pub fn post(
210209
&self,
211210
url: Url,
212-
body: deno_fetch::ReqBody,
211+
body: deno_web::fetch::ReqBody,
213212
) -> Result<RequestBuilder, http::Error> {
214213
let mut req = http::Request::new(body);
215214
*req.method_mut() = http::Method::POST;
@@ -229,7 +228,7 @@ impl HttpClient {
229228
S: serde::Serialize,
230229
{
231230
let json = deno_core::serde_json::to_vec(ser)?;
232-
let body = deno_fetch::ReqBody::full(json.into());
231+
let body = deno_web::fetch::ReqBody::full(json.into());
233232
let builder = self.post(url, body)?;
234233
Ok(builder.header(
235234
http::header::CONTENT_TYPE,
@@ -242,7 +241,7 @@ impl HttpClient {
242241
url: &Url,
243242
headers: HeaderMap,
244243
) -> Result<http::Response<ResBody>, SendError> {
245-
let body = deno_fetch::ReqBody::empty();
244+
let body = deno_web::fetch::ReqBody::empty();
246245
let mut request = http::Request::new(body);
247246
*request.uri_mut() = http::Uri::try_from(url.as_str())?;
248247
*request.headers_mut() = headers;
@@ -328,7 +327,8 @@ impl HttpClient {
328327
&self,
329328
mut url: Url,
330329
headers: &HeaderMap<HeaderValue>,
331-
) -> Result<(http::Response<deno_fetch::ResBody>, Url), DownloadError> {
330+
) -> Result<(http::Response<deno_web::fetch::ResBody>, Url), DownloadError>
331+
{
332332
let mut req = self.get(url.clone())?.build();
333333
*req.headers_mut() = headers.clone();
334334
let mut response = self
@@ -372,7 +372,7 @@ impl HttpClient {
372372
}
373373

374374
pub async fn get_response_body_with_progress(
375-
response: http::Response<deno_fetch::ResBody>,
375+
response: http::Response<deno_web::fetch::ResBody>,
376376
progress_guard: Option<&UpdateGuard>,
377377
) -> Result<(HeaderMap, Vec<u8>), JsErrorBox> {
378378
use http_body::Body as _;
@@ -440,8 +440,8 @@ where
440440
}
441441

442442
pub struct RequestBuilder {
443-
client: deno_fetch::Client,
444-
req: http::Request<deno_fetch::ReqBody>,
443+
client: deno_web::fetch::Client,
444+
req: http::Request<deno_web::fetch::ReqBody>,
445445
}
446446

447447
impl RequestBuilder {
@@ -452,11 +452,11 @@ impl RequestBuilder {
452452

453453
pub async fn send(
454454
self,
455-
) -> Result<http::Response<deno_fetch::ResBody>, AnyError> {
455+
) -> Result<http::Response<deno_web::fetch::ResBody>, AnyError> {
456456
self.client.send(self.req).await.map_err(Into::into)
457457
}
458458

459-
pub fn build(self) -> http::Request<deno_fetch::ReqBody> {
459+
pub fn build(self) -> http::Request<deno_web::fetch::ReqBody> {
460460
self.req
461461
}
462462
}

cli/registry.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use deno_core::error::AnyError;
44
use deno_core::serde_json;
55
use deno_core::url::Url;
6-
use deno_runtime::deno_fetch;
76
use serde::de::DeserializeOwned;
87

98
use crate::http_util;
@@ -89,7 +88,7 @@ impl std::fmt::Debug for ApiError {
8988
impl std::error::Error for ApiError {}
9089

9190
pub async fn parse_response<T: DeserializeOwned>(
92-
response: http::Response<deno_fetch::ResBody>,
91+
response: http::Response<deno_web::fetch::ResBody>,
9392
) -> Result<T, ApiError> {
9493
let status = response.status();
9594
let x_deno_ray = response
@@ -138,7 +137,7 @@ pub async fn get_package(
138137
registry_api_url: &Url,
139138
scope: &str,
140139
package: &str,
141-
) -> Result<http::Response<deno_fetch::ResBody>, AnyError> {
140+
) -> Result<http::Response<deno_web::fetch::ResBody>, AnyError> {
142141
let package_url = get_package_api_url(registry_api_url, scope, package);
143142
let response = client.get(package_url.parse()?)?.send().await?;
144143
Ok(response)

cli/tools/publish/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use deno_core::serde_json::Value;
2828
use deno_core::serde_json::json;
2929
use deno_core::url::Url;
3030
use deno_resolver::collections::FolderScopedMap;
31-
use deno_runtime::deno_fetch;
3231
use deno_terminal::colors;
3332
use http_body_util::BodyExt;
3433
use serde::Deserialize;
@@ -923,7 +922,7 @@ async fn publish_package(
923922
package.config
924923
);
925924

926-
let body = deno_fetch::ReqBody::full(package.tarball.bytes.clone());
925+
let body = deno_web::fetch::ReqBody::full(package.tarball.bytes.clone());
927926
let response = http_client
928927
.post(url.parse()?, body)?
929928
.header(

cli/tools/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ pub fn worker_prepare_for_test(worker: &mut MainWorker) {
832832
.js_runtime
833833
.op_state()
834834
.borrow_mut()
835-
.try_take::<deno_runtime::deno_fetch::Client>();
835+
.try_take::<deno_web::fetch::Client>();
836836
}
837837

838838
/// Yields to tokio to allow async work to process, and then polls

0 commit comments

Comments
 (0)