@@ -21,13 +21,34 @@ pub use attohttpc::header;
2121
2222use header:: { HeaderName , HeaderValue } ;
2323
24+ #[ derive( Deserialize ) ]
25+ #[ serde( untagged) ]
26+ enum SerdeDuration {
27+ Seconds ( u64 ) ,
28+ Duration ( Duration ) ,
29+ }
30+
31+ fn deserialize_duration < ' de , D : Deserializer < ' de > > (
32+ deserializer : D ,
33+ ) -> Result < Option < Duration > , D :: Error > {
34+ if let Some ( duration) = Option :: < SerdeDuration > :: deserialize ( deserializer) ? {
35+ Ok ( Some ( match duration {
36+ SerdeDuration :: Seconds ( s) => Duration :: from_secs ( s) ,
37+ SerdeDuration :: Duration ( d) => d,
38+ } ) )
39+ } else {
40+ Ok ( None )
41+ }
42+ }
43+
2444/// The builder of [`Client`].
2545#[ derive( Debug , Clone , Default , Deserialize ) ]
2646#[ serde( rename_all = "camelCase" ) ]
2747pub struct ClientBuilder {
2848 /// Max number of redirections to follow.
2949 pub max_redirections : Option < usize > ,
3050 /// Connect timeout for the request.
51+ #[ serde( deserialize_with = "deserialize_duration" ) ]
3152 pub connect_timeout : Option < Duration > ,
3253}
3354
@@ -448,6 +469,7 @@ pub struct HttpRequestBuilder {
448469 /// The request body
449470 pub body : Option < Body > ,
450471 /// Timeout for the whole request
472+ #[ serde( deserialize_with = "deserialize_duration" ) ]
451473 pub timeout : Option < Duration > ,
452474 /// The response type (defaults to Json)
453475 pub response_type : Option < ResponseType > ,
0 commit comments