diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/file_fetcher.rs | 93 | ||||
-rw-r--r-- | cli/http_util.rs | 28 | ||||
-rw-r--r-- | cli/tests/unit/fetch_test.ts | 34 | ||||
-rw-r--r-- | cli/tsc/dts/lib.deno.unstable.d.ts | 9 |
4 files changed, 100 insertions, 64 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index fd8c0f793..71d284ef6 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -744,6 +744,7 @@ mod tests { use deno_core::resolve_url; use deno_core::url::Url; use deno_runtime::deno_fetch::create_http_client; + use deno_runtime::deno_fetch::CreateHttpClientOptions; use deno_runtime::deno_web::Blob; use deno_runtime::deno_web::InMemoryBlobPart; use std::fs::read; @@ -1746,7 +1747,7 @@ mod tests { fn create_test_client() -> HttpClient { HttpClient::from_client( - create_http_client("test_client", None, vec![], None, None, None) + create_http_client("test_client", CreateHttpClientOptions::default()) .unwrap(), ) } @@ -1943,17 +1944,16 @@ mod tests { let client = HttpClient::from_client( create_http_client( version::get_user_agent(), - None, - vec![read( - test_util::testdata_path() - .join("tls/RootCA.pem") - .to_str() - .unwrap(), - ) - .unwrap()], - None, - None, - None, + CreateHttpClientOptions { + ca_certs: vec![read( + test_util::testdata_path() + .join("tls/RootCA.pem") + .to_str() + .unwrap(), + ) + .unwrap()], + ..Default::default() + }, ) .unwrap(), ); @@ -1986,11 +1986,7 @@ mod tests { let client = HttpClient::from_client( create_http_client( version::get_user_agent(), - None, // This will load mozilla certs by default - vec![], - None, - None, - None, + CreateHttpClientOptions::default(), ) .unwrap(), ); @@ -2068,17 +2064,16 @@ mod tests { let client = HttpClient::from_client( create_http_client( version::get_user_agent(), - None, - vec![read( - test_util::testdata_path() - .join("tls/RootCA.pem") - .to_str() - .unwrap(), - ) - .unwrap()], - None, - None, - None, + CreateHttpClientOptions { + ca_certs: vec![read( + test_util::testdata_path() + .join("tls/RootCA.pem") + .to_str() + .unwrap(), + ) + .unwrap()], + ..Default::default() + }, ) .unwrap(), ); @@ -2113,17 +2108,16 @@ mod tests { let client = HttpClient::from_client( create_http_client( version::get_user_agent(), - None, - vec![read( - test_util::testdata_path() - .join("tls/RootCA.pem") - .to_str() - .unwrap(), - ) - .unwrap()], - None, - None, - None, + CreateHttpClientOptions { + ca_certs: vec![read( + test_util::testdata_path() + .join("tls/RootCA.pem") + .to_str() + .unwrap(), + ) + .unwrap()], + ..Default::default() + }, ) .unwrap(), ); @@ -2175,17 +2169,16 @@ mod tests { let client = HttpClient::from_client( create_http_client( version::get_user_agent(), - None, - vec![read( - test_util::testdata_path() - .join("tls/RootCA.pem") - .to_str() - .unwrap(), - ) - .unwrap()], - None, - None, - None, + CreateHttpClientOptions { + ca_certs: vec![read( + test_util::testdata_path() + .join("tls/RootCA.pem") + .to_str() + .unwrap(), + ) + .unwrap()], + ..Default::default() + }, ) .unwrap(), ); diff --git a/cli/http_util.rs b/cli/http_util.rs index 7c17e8e1e..e90e0ee96 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -15,6 +15,7 @@ use deno_runtime::deno_fetch::create_http_client; use deno_runtime::deno_fetch::reqwest; use deno_runtime::deno_fetch::reqwest::header::LOCATION; use deno_runtime::deno_fetch::reqwest::Response; +use deno_runtime::deno_fetch::CreateHttpClientOptions; use deno_runtime::deno_tls::RootCertStoreProvider; use std::collections::HashMap; use std::sync::Arc; @@ -219,18 +220,15 @@ impl CacheSemantics { } pub struct HttpClient { + options: CreateHttpClientOptions, root_cert_store_provider: Option<Arc<dyn RootCertStoreProvider>>, - unsafely_ignore_certificate_errors: Option<Vec<String>>, cell: once_cell::sync::OnceCell<reqwest::Client>, } impl std::fmt::Debug for HttpClient { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("HttpClient") - .field( - "unsafely_ignore_certificate_errors", - &self.unsafely_ignore_certificate_errors, - ) + .field("options", &self.options) .finish() } } @@ -241,8 +239,11 @@ impl HttpClient { unsafely_ignore_certificate_errors: Option<Vec<String>>, ) -> Self { Self { + options: CreateHttpClientOptions { + unsafely_ignore_certificate_errors, + ..Default::default() + }, root_cert_store_provider, - unsafely_ignore_certificate_errors, cell: Default::default(), } } @@ -250,8 +251,8 @@ impl HttpClient { #[cfg(test)] pub fn from_client(client: reqwest::Client) -> Self { let result = Self { + options: Default::default(), root_cert_store_provider: Default::default(), - unsafely_ignore_certificate_errors: Default::default(), cell: Default::default(), }; result.cell.set(client).unwrap(); @@ -262,14 +263,13 @@ impl HttpClient { self.cell.get_or_try_init(|| { create_http_client( get_user_agent(), - match &self.root_cert_store_provider { - Some(provider) => Some(provider.get_or_try_init()?.clone()), - None => None, + CreateHttpClientOptions { + root_cert_store: match &self.root_cert_store_provider { + Some(provider) => Some(provider.get_or_try_init()?.clone()), + None => None, + }, + ..self.options.clone() }, - vec![], - None, - self.unsafely_ignore_certificate_errors.clone(), - None, ) }) } diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 7de04013e..d86795578 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1532,6 +1532,40 @@ Deno.test( ); Deno.test( + { + permissions: { net: true, read: true }, + // Doesn't pass on linux CI for unknown reasons (works fine locally on linux) + ignore: Deno.build.os !== "darwin", + }, + async function fetchForceHttp1OnHttp2Server() { + const client = Deno.createHttpClient({ http2: false, http1: true }); + await assertRejects( + () => fetch("http://localhost:5549/http_version", { client }), + TypeError, + "invalid HTTP version parsed", + ); + client.close(); + }, +); + +Deno.test( + { + permissions: { net: true, read: true }, + // Doesn't pass on linux CI for unknown reasons (works fine locally on linux) + ignore: Deno.build.os !== "darwin", + }, + async function fetchForceHttp2OnHttp1Server() { + const client = Deno.createHttpClient({ http2: true, http1: false }); + await assertRejects( + () => fetch("http://localhost:5548/http_version", { client }), + TypeError, + "stream closed because of a broken pipe", + ); + client.close(); + }, +); + +Deno.test( { permissions: { net: true, read: true } }, async function fetchPrefersHttp2() { const caCert = await Deno.readTextFile("cli/tests/testdata/tls/RootCA.pem"); diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 70d7ef7c4..8681cbd9b 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -821,6 +821,15 @@ declare namespace Deno { certChain?: string; /** PEM formatted (RSA or PKCS8) private key of client certificate. */ privateKey?: string; + /** Sets the maximum numer of idle connections per host allowed in the pool. */ + poolMaxIdlePerHost?: number; + /** Set an optional timeout for idle sockets being kept-alive. + * Set to false to disable the timeout. */ + poolIdleTimeout?: number | false; + /** Whether HTTP/1.1 is allowed or not. */ + http1?: boolean; + /** Whether HTTP/2 is allowed or not. */ + http2?: boolean; } /** **UNSTABLE**: New API, yet to be vetted. |