From 8ba828b41e2609c91d993aec464035d62320fdad Mon Sep 17 00:00:00 2001 From: Raashid Anwar Date: Sun, 31 Dec 2023 18:15:12 +0530 Subject: [PATCH] fix(http_client): Fix Deno.createHttpClient to accept poolIdleTimeout parameter (#21603) Fixed the bug `Deno.createHttpClient` to accept `poolIdleTimeout` parameter. Fixes https://github.com/denoland/deno/issues/21546 --- Cargo.lock | 1 + cli/tests/unit/fetch_test.ts | 10 ++++++++++ ext/fetch/Cargo.toml | 1 + ext/fetch/lib.rs | 18 +++++++----------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba7c894604..6b491ac095 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1261,6 +1261,7 @@ dependencies = [ "pin-project", "reqwest", "serde", + "serde_json", "tokio", "tokio-util", ] diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index b4d2484409..bd105cb3f0 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1159,6 +1159,16 @@ Deno.test( }, ); +Deno.test( + { permissions: { net: true, read: true } }, + function createHttpClientAcceptPoolIdleTimeout() { + const client = Deno.createHttpClient({ + poolIdleTimeout: 1000, + }); + client.close(); + }, +); + Deno.test( { permissions: { net: true } }, async function fetchCustomClientUserAgent(): Promise< diff --git a/ext/fetch/Cargo.toml b/ext/fetch/Cargo.toml index af4af29a64..2e3283b085 100644 --- a/ext/fetch/Cargo.toml +++ b/ext/fetch/Cargo.toml @@ -23,5 +23,6 @@ http_v02.workspace = true pin-project.workspace = true reqwest.workspace = true serde.workspace = true +serde_json.workspace = true tokio.workspace = true tokio-util = { workspace = true, features = ["io"] } diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 6a2ac2ef98..ee8f30b59b 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -789,13 +789,6 @@ impl HttpClientResource { } } -#[derive(Deserialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] -pub enum PoolIdleTimeout { - State(bool), - Specify(u64), -} - #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct CreateHttpClientArgs { @@ -804,7 +797,7 @@ pub struct CreateHttpClientArgs { cert_chain: Option, private_key: Option, pool_max_idle_per_host: Option, - pool_idle_timeout: Option, + pool_idle_timeout: Option, #[serde(default = "default_true")] http1: bool, #[serde(default = "default_true")] @@ -867,9 +860,12 @@ where pool_max_idle_per_host: args.pool_max_idle_per_host, pool_idle_timeout: args.pool_idle_timeout.and_then( |timeout| match timeout { - PoolIdleTimeout::State(true) => None, - PoolIdleTimeout::State(false) => Some(None), - PoolIdleTimeout::Specify(specify) => Some(Some(specify)), + serde_json::Value::Bool(true) => None, + serde_json::Value::Bool(false) => Some(None), + serde_json::Value::Number(specify) => { + Some(Some(specify.as_u64().unwrap_or_default())) + } + _ => Some(None), }, ), http1: args.http1,