1
1
//! Configuration for `HttpClient`s.
2
2
3
+ use std:: fmt:: Debug ;
3
4
use std:: time:: Duration ;
4
5
5
6
/// Configuration for `HttpClient`s.
6
7
#[ non_exhaustive]
7
- #[ derive( Clone , Debug ) ]
8
+ #[ derive( Clone ) ]
8
9
pub struct Config {
9
10
/// HTTP/1.1 `keep-alive` (connection pooling).
10
11
///
@@ -18,6 +19,37 @@ pub struct Config {
18
19
///
19
20
/// Default: `Some(Duration::from_secs(60))`.
20
21
pub timeout : Option < Duration > ,
22
+ /// TLS Configuration (Rustls)
23
+ #[ cfg( all( feature = "h1_client" , feature = "rustls" ) ) ]
24
+ pub tls_config : Option < std:: sync:: Arc < rustls_crate:: ClientConfig > > ,
25
+ /// TLS Configuration (Native TLS)
26
+ #[ cfg( all( feature = "h1_client" , feature = "native-tls" , not( feature = "rustls" ) ) ) ]
27
+ pub tls_config : Option < std:: sync:: Arc < async_native_tls:: TlsConnector > > ,
28
+ }
29
+
30
+ impl Debug for Config {
31
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
32
+ let mut dbg_struct = f. debug_struct ( "Config" ) ;
33
+ dbg_struct
34
+ . field ( "http_keep_alive" , & self . http_keep_alive )
35
+ . field ( "tcp_no_delay" , & self . tcp_no_delay )
36
+ . field ( "timeout" , & self . timeout ) ;
37
+
38
+ #[ cfg( all( feature = "h1_client" , feature = "rustls" ) ) ]
39
+ {
40
+ if self . tls_config . is_some ( ) {
41
+ dbg_struct. field ( "tls_config" , & "Some(rustls::ClientConfig)" ) ;
42
+ } else {
43
+ dbg_struct. field ( "tls_config" , & "None" ) ;
44
+ }
45
+ }
46
+ #[ cfg( all( feature = "h1_client" , feature = "native-tls" , not( feature = "rustls" ) ) ) ]
47
+ {
48
+ dbg_struct. field ( "tls_config" , & self . tls_config ) ;
49
+ }
50
+
51
+ dbg_struct. finish ( )
52
+ }
21
53
}
22
54
23
55
impl Config {
@@ -27,6 +59,8 @@ impl Config {
27
59
http_keep_alive : true ,
28
60
tcp_no_delay : false ,
29
61
timeout : Some ( Duration :: from_secs ( 60 ) ) ,
62
+ #[ cfg( all( feature = "h1_client" , any( feature = "rustls" , feature = "native-tls" ) ) ) ]
63
+ tls_config : None ,
30
64
}
31
65
}
32
66
}
@@ -55,4 +89,23 @@ impl Config {
55
89
self . timeout = timeout;
56
90
self
57
91
}
92
+
93
+ /// Set TLS Configuration (Rustls)
94
+ #[ cfg( all( feature = "h1_client" , feature = "rustls" ) ) ]
95
+ pub fn set_tls_config (
96
+ mut self ,
97
+ tls_config : Option < std:: sync:: Arc < rustls_crate:: ClientConfig > > ,
98
+ ) -> Self {
99
+ self . tls_config = tls_config;
100
+ self
101
+ }
102
+ /// Set TLS Configuration (Native TLS)
103
+ #[ cfg( all( feature = "h1_client" , feature = "native-tls" , not( feature = "rustls" ) ) ) ]
104
+ pub fn set_tls_config (
105
+ mut self ,
106
+ tls_config : Option < std:: sync:: Arc < async_native_tls:: TlsConnector > > ,
107
+ ) -> Self {
108
+ self . tls_config = tls_config;
109
+ self
110
+ }
58
111
}
0 commit comments