1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

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
This commit is contained in:
Raashid Anwar 2023-12-31 18:15:12 +05:30 committed by Bartek Iwańczuk
parent ce539e9189
commit 857cf1f154
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
4 changed files with 19 additions and 11 deletions

1
Cargo.lock generated
View file

@ -1261,6 +1261,7 @@ dependencies = [
"pin-project",
"reqwest",
"serde",
"serde_json",
"tokio",
"tokio-util",
]

View file

@ -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<

View file

@ -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"] }

View file

@ -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<String>,
private_key: Option<String>,
pool_max_idle_per_host: Option<usize>,
pool_idle_timeout: Option<PoolIdleTimeout>,
pool_idle_timeout: Option<serde_json::Value>,
#[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,