1
1
{ {> partial_header} }
2
2
use hyper;
3
+ use hyper_util::client::legacy::Client;
4
+ use hyper_util::client::legacy::connect::Connect;
5
+ use hyper_util::client::legacy::connect::HttpConnector;
6
+ use hyper_util::rt::TokioExecutor;
3
7
4
- pub struct Configuration<C: hyper::client::connect:: Connect >
8
+ pub struct Configuration<C: Connect = HttpConnector >
5
9
where C: Clone + std::marker::Send + Sync + 'static {
6
10
pub base_path: String,
7
11
pub user_agent: Option< String> ,
8
- pub client: hyper::client:: Client< C> ,
12
+ pub client: Client< C, String > ,
9
13
pub basic_auth: Option< BasicAuth> ,
10
14
pub oauth_access_token: Option< String> ,
11
15
pub api_key: Option< ApiKey> ,
@@ -19,9 +23,41 @@ pub struct ApiKey {
19
23
pub key: String,
20
24
}
21
25
22
- impl<C: hyper::client::connect::Connect > Configuration<C >
26
+ impl Configuration<HttpConnector > {
27
+ /// Construct a default [`Configuration`](Self) with a hyper client using a default
28
+ /// [`HttpConnector`](hyper_util::client::legacy::connect::HttpConnector).
29
+ ///
30
+ /// Use [`with_client`](Configuration< T> ::with_client) to construct a Configuration with a
31
+ /// custom hyper client.
32
+ ///
33
+ /// # Example
34
+ ///
35
+ /// ```
36
+ /// let api_config = {
37
+ /// api_key: " my-api-key" ,
38
+ /// ...Configuration::new()
39
+ /// }
40
+ /// ```
41
+ pub fn new() -> Configuration<HttpConnector > {
42
+ Configuration::default ()
43
+ }
44
+ }
45
+
46
+ impl<C: Connect > Configuration<C >
23
47
where C: Clone + std::marker::Send + Sync {
24
- pub fn new(client: hyper::client::Client< C> ) -> Configuration< C> {
48
+
49
+ /// Construct a new Configuration with a custom hyper client.
50
+ ///
51
+ /// # Example
52
+ ///
53
+ /// ```
54
+ /// let client = Client::builder(TokioExecutor::new())
55
+ /// .pool_idle_timeout(Duration::from_secs(30))
56
+ /// .build_http();
57
+ ///
58
+ /// let api_config = Configuration::with_client(client);
59
+ /// ```
60
+ pub fn with_client(client: Client< C, String> ) -> Configuration< C> {
25
61
Configuration {
26
62
base_path: " {{{basePath}}}" .to_owned(),
27
63
user_agent: {{#httpUserAgent} }Some("{ {{.} }}".to_owned()){ {/httpUserAgent} }{ {^httpUserAgent} }Some("OpenAPI-Generator/{ {{version} }}/rust".to_owned()){ {/httpUserAgent} },
@@ -32,3 +68,10 @@ impl<C: hyper::client::connect::Connect> Configuration<C>
32
68
}
33
69
}
34
70
}
71
+
72
+ impl Default for Configuration<HttpConnector > {
73
+ fn default () -> Self {
74
+ let client = Client::builder(TokioExecutor::new()).build_http();
75
+ Configuration::with_client(client)
76
+ }
77
+ }
0 commit comments