mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
This commit is contained in:
committed by
GitHub
parent
ad1786178a
commit
f3c5ca89e7
5
.changes/fix-api-timeout-type.md
Normal file
5
.changes/fix-api-timeout-type.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Fixes the type of `http > connectTimeout`.
|
||||
5
.changes/http-timeout-serde-fix.md
Normal file
5
.changes/http-timeout-serde-fix.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Deserialize numeric values (seconds) in the http API `ClientBuilder.connect_timeout` and `HttpRequestBuilder.timeout` fields.
|
||||
@@ -21,6 +21,26 @@ pub use attohttpc::header;
|
||||
|
||||
use header::{HeaderName, HeaderValue};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum SerdeDuration {
|
||||
Seconds(u64),
|
||||
Duration(Duration),
|
||||
}
|
||||
|
||||
fn deserialize_duration<'de, D: Deserializer<'de>>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<Duration>, D::Error> {
|
||||
if let Some(duration) = Option::<SerdeDuration>::deserialize(deserializer)? {
|
||||
Ok(Some(match duration {
|
||||
SerdeDuration::Seconds(s) => Duration::from_secs(s),
|
||||
SerdeDuration::Duration(d) => d,
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// The builder of [`Client`].
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -28,6 +48,7 @@ pub struct ClientBuilder {
|
||||
/// Max number of redirections to follow.
|
||||
pub max_redirections: Option<usize>,
|
||||
/// Connect timeout for the request.
|
||||
#[serde(deserialize_with = "deserialize_duration")]
|
||||
pub connect_timeout: Option<Duration>,
|
||||
}
|
||||
|
||||
@@ -448,6 +469,7 @@ pub struct HttpRequestBuilder {
|
||||
/// The request body
|
||||
pub body: Option<Body>,
|
||||
/// Timeout for the whole request
|
||||
#[serde(deserialize_with = "deserialize_duration")]
|
||||
pub timeout: Option<Duration>,
|
||||
/// The response type (defaults to Json)
|
||||
pub response_type: Option<ResponseType>,
|
||||
|
||||
@@ -45,9 +45,14 @@
|
||||
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
|
||||
interface Duration {
|
||||
secs: number
|
||||
nanos: number
|
||||
}
|
||||
|
||||
interface ClientOptions {
|
||||
maxRedirections: number
|
||||
connectTimeout: number
|
||||
connectTimeout: number | Duration
|
||||
}
|
||||
|
||||
enum ResponseType {
|
||||
@@ -177,7 +182,7 @@ interface HttpOptions {
|
||||
headers?: Record<string, any>
|
||||
query?: Record<string, any>
|
||||
body?: Body
|
||||
timeout?: number
|
||||
timeout?: number | Duration
|
||||
responseType?: ResponseType
|
||||
}
|
||||
|
||||
@@ -417,6 +422,7 @@ async function fetch<T>(
|
||||
}
|
||||
|
||||
export type {
|
||||
Duration,
|
||||
ClientOptions,
|
||||
Part,
|
||||
HttpVerb,
|
||||
|
||||
Reference in New Issue
Block a user