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:
parent
ce539e9189
commit
857cf1f154
4 changed files with 19 additions and 11 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1261,6 +1261,7 @@ dependencies = [
|
|||
"pin-project",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
]
|
||||
|
|
|
@ -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<
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue