Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 32 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ members = [
"ext/canvas",
"ext/cron",
"ext/crypto",
"ext/fetch",
"ext/ffi",
"ext/fs",
"ext/http",
Expand Down Expand Up @@ -91,7 +90,6 @@ deno_cache = { version = "0.153.0", path = "./ext/cache" }
deno_canvas = { version = "0.90.0", path = "./ext/canvas" }
deno_cron = { version = "0.101.0", path = "./ext/cron" }
deno_crypto = { version = "0.235.0", path = "./ext/crypto" }
deno_fetch = { version = "0.245.0", path = "./ext/fetch" }
deno_ffi = { version = "0.208.0", path = "./ext/ffi" }
deno_fs = { version = "0.131.0", path = "./ext/fs" }
deno_http = { version = "0.219.0", path = "./ext/http" }
Expand Down Expand Up @@ -443,8 +441,6 @@ opt-level = 3
opt-level = 3
[profile.release.package.deno_crypto]
opt-level = 3
[profile.release.package.deno_fetch]
opt-level = 3
[profile.release.package.deno_ffi]
opt-level = 3
[profile.release.package.deno_http]
Expand Down
41 changes: 22 additions & 19 deletions cli/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use deno_core::url::Url;
use deno_error::JsError;
use deno_error::JsErrorBox;
use deno_lib::version::DENO_VERSION_INFO;
use deno_runtime::deno_fetch;
use deno_runtime::deno_fetch::CreateHttpClientOptions;
use deno_runtime::deno_fetch::ResBody;
use deno_runtime::deno_fetch::create_http_client;
use deno_runtime::deno_tls::RootCertStoreProvider;
use deno_runtime::deno_web::fetch::CreateHttpClientOptions;
use deno_runtime::deno_web::fetch::ResBody;
use deno_runtime::deno_web::fetch::create_http_client;
use http::HeaderMap;
use http::StatusCode;
use http::header::CONTENT_LENGTH;
Expand All @@ -31,15 +30,15 @@ use crate::util::progress_bar::UpdateGuard;
#[derive(Debug, Error)]
pub enum SendError {
#[error(transparent)]
Send(#[from] deno_fetch::ClientSendError),
Send(#[from] deno_runtime::deno_web::fetch::ClientSendError),
#[error(transparent)]
InvalidUri(#[from] http::uri::InvalidUri),
}

pub struct HttpClientProvider {
options: CreateHttpClientOptions,
root_cert_store_provider: Option<Arc<dyn RootCertStoreProvider>>,
client: OnceCell<deno_fetch::Client>,
client: OnceCell<deno_runtime::deno_web::fetch::Client>,
}

impl std::fmt::Debug for HttpClientProvider {
Expand Down Expand Up @@ -98,7 +97,7 @@ pub struct DownloadError(pub Box<DownloadErrorKind>);
pub enum DownloadErrorKind {
#[class(inherit)]
#[error(transparent)]
Fetch(deno_fetch::ClientSendError),
Fetch(deno_runtime::deno_web::fetch::ClientSendError),
#[class(inherit)]
#[error(transparent)]
UrlParse(#[from] deno_core::url::ParseError),
Expand Down Expand Up @@ -165,18 +164,18 @@ impl HttpClientResponse {

#[derive(Debug)]
pub struct HttpClient {
client: deno_fetch::Client,
client: deno_runtime::deno_web::fetch::Client,
}

impl HttpClient {
// DO NOT make this public. You should always be creating one of these from
// the HttpClientProvider
fn new(client: deno_fetch::Client) -> Self {
fn new(client: deno_runtime::deno_web::fetch::Client) -> Self {
Self { client }
}

pub fn get(&self, url: Url) -> Result<RequestBuilder, http::Error> {
let body = deno_fetch::ReqBody::empty();
let body = deno_runtime::deno_web::fetch::ReqBody::empty();
let mut req = http::Request::new(body);
*req.uri_mut() = url.as_str().parse()?;
Ok(RequestBuilder {
Expand All @@ -188,7 +187,7 @@ impl HttpClient {
pub fn post(
&self,
url: Url,
body: deno_fetch::ReqBody,
body: deno_runtime::deno_web::fetch::ReqBody,
) -> Result<RequestBuilder, http::Error> {
let mut req = http::Request::new(body);
*req.method_mut() = http::Method::POST;
Expand All @@ -208,7 +207,7 @@ impl HttpClient {
S: serde::Serialize,
{
let json = deno_core::serde_json::to_vec(ser)?;
let body = deno_fetch::ReqBody::full(json.into());
let body = deno_runtime::deno_web::fetch::ReqBody::full(json.into());
let builder = self.post(url, body)?;
Ok(builder.header(
http::header::CONTENT_TYPE,
Expand All @@ -221,7 +220,7 @@ impl HttpClient {
url: &Url,
headers: HeaderMap,
) -> Result<http::Response<ResBody>, SendError> {
let body = deno_fetch::ReqBody::empty();
let body = deno_runtime::deno_web::fetch::ReqBody::empty();
let mut request = http::Request::new(body);
*request.uri_mut() = http::Uri::try_from(url.as_str())?;
*request.headers_mut() = headers;
Expand Down Expand Up @@ -307,7 +306,10 @@ impl HttpClient {
&self,
mut url: Url,
headers: &HeaderMap<HeaderValue>,
) -> Result<(http::Response<deno_fetch::ResBody>, Url), DownloadError> {
) -> Result<
(http::Response<deno_runtime::deno_web::fetch::ResBody>, Url),
DownloadError,
> {
let mut req = self.get(url.clone())?.build();
*req.headers_mut() = headers.clone();
let mut response = self
Expand Down Expand Up @@ -351,7 +353,7 @@ impl HttpClient {
}

pub async fn get_response_body_with_progress(
response: http::Response<deno_fetch::ResBody>,
response: http::Response<deno_runtime::deno_web::fetch::ResBody>,
progress_guard: Option<&UpdateGuard>,
) -> Result<(HeaderMap, Vec<u8>), JsErrorBox> {
use http_body::Body as _;
Expand Down Expand Up @@ -419,8 +421,8 @@ where
}

pub struct RequestBuilder {
client: deno_fetch::Client,
req: http::Request<deno_fetch::ReqBody>,
client: deno_runtime::deno_web::fetch::Client,
req: http::Request<deno_runtime::deno_web::fetch::ReqBody>,
}

impl RequestBuilder {
Expand All @@ -431,11 +433,12 @@ impl RequestBuilder {

pub async fn send(
self,
) -> Result<http::Response<deno_fetch::ResBody>, AnyError> {
) -> Result<http::Response<deno_runtime::deno_web::fetch::ResBody>, AnyError>
{
self.client.send(self.req).await.map_err(Into::into)
}

pub fn build(self) -> http::Request<deno_fetch::ReqBody> {
pub fn build(self) -> http::Request<deno_runtime::deno_web::fetch::ReqBody> {
self.req
}
}
Expand Down
5 changes: 2 additions & 3 deletions cli/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::url::Url;
use deno_runtime::deno_fetch;
use serde::de::DeserializeOwned;

use crate::http_util;
Expand Down Expand Up @@ -89,7 +88,7 @@ impl std::fmt::Debug for ApiError {
impl std::error::Error for ApiError {}

pub async fn parse_response<T: DeserializeOwned>(
response: http::Response<deno_fetch::ResBody>,
response: http::Response<deno_runtime::deno_web::fetch::ResBody>,
) -> Result<T, ApiError> {
let status = response.status();
let x_deno_ray = response
Expand Down Expand Up @@ -138,7 +137,7 @@ pub async fn get_package(
registry_api_url: &Url,
scope: &str,
package: &str,
) -> Result<http::Response<deno_fetch::ResBody>, AnyError> {
) -> Result<http::Response<deno_runtime::deno_web::fetch::ResBody>, AnyError> {
let package_url = get_package_api_url(registry_api_url, scope, package);
let response = client.get(package_url.parse()?)?.send().await?;
Ok(response)
Expand Down
4 changes: 2 additions & 2 deletions cli/tools/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use deno_core::serde_json::Value;
use deno_core::serde_json::json;
use deno_core::url::Url;
use deno_resolver::collections::FolderScopedMap;
use deno_runtime::deno_fetch;
use deno_terminal::colors;
use http_body_util::BodyExt;
use serde::Deserialize;
Expand Down Expand Up @@ -923,7 +922,8 @@ async fn publish_package(
package.config
);

let body = deno_fetch::ReqBody::full(package.tarball.bytes.clone());
let body =
deno_runtime::deno_web::fetch::ReqBody::full(package.tarball.bytes.clone());
let response = http_client
.post(url.parse()?, body)?
.header(
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ pub fn worker_prepare_for_test(worker: &mut MainWorker) {
.js_runtime
.op_state()
.borrow_mut()
.try_take::<deno_runtime::deno_fetch::Client>();
.try_take::<deno_runtime::deno_web::fetch::Client>();
}

/// Yields to tokio to allow async work to process, and then polls
Expand Down
6 changes: 3 additions & 3 deletions ext/cache/01_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
Request,
RequestPrototype,
toInnerRequest,
} from "ext:deno_fetch/23_request.js";
import { toInnerResponse } from "ext:deno_fetch/23_response.js";
} from "ext:deno_web/23_request.js";
import { toInnerResponse } from "ext:deno_web/23_response.js";
import { URLPrototype } from "ext:deno_web/00_url.js";
import { getHeader } from "ext:deno_fetch/20_headers.js";
import { getHeader } from "ext:deno_web/20_headers.js";
import {
getReadableStreamResourceBacking,
readableStreamForRid,
Expand Down
1 change: 1 addition & 0 deletions ext/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bytes.workspace = true
chrono = { workspace = true, features = ["now"] }
deno_core.workspace = true
deno_error.workspace = true
deno_web.workspace = true
futures.workspace = true
http.workspace = true
http-body.workspace = true
Expand Down
Loading
Loading