1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use crate::api_common::Error;
use http::header;
use http::request::Builder;
use http::request::Request;
use http::Response;
use hyper::body::Incoming;
use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::client::legacy::Error as HyperError;
use hyper_util::rt::TokioExecutor;
use std::future::Future;
use std::pin::Pin;
pub trait Connector: Connect + Clone + Send + Sync + 'static {}
impl Connector for HttpConnector {}
pub trait HasConfig {
    fn get_config(&self) -> &dyn ClientConfig;
}
pub trait ClientConfig: Send + Sync {
    fn get_base_path(&self) -> &String;
    fn get_user_agent(&self) -> &Option<String>;
    fn request<'a>(
        &self,
        request: Request<String>,
    ) -> Pin<Box<dyn Future<Output = Result<Response<Incoming>, HyperError>> + 'a + Send>>;
    fn req_builder(&self, method: &str) -> Result<Builder, Error> {
        let mut req_builder = hyper::Request::builder().method(method);
        if let Some(user_agent) = self.get_user_agent() {
            req_builder = req_builder.header(header::USER_AGENT, user_agent);
        }
        Ok(req_builder)
    }
}
pub struct Config<C: Connector = HttpConnector> {
    pub base_path: String,
    pub user_agent: Option<String>,
    pub client: Client<C, String>,
}
impl Config<HttpConnector> {
    pub fn new() -> Config<HttpConnector> {
        Config::default()
    }
}
impl Default for Config<HttpConnector> {
    fn default() -> Self {
        let client = Client::builder(TokioExecutor::new()).build_http();
        Config::with_client(client)
    }
}
impl<C: Connector> Config<C> {
    pub fn with_client(client: Client<C, String>) -> Config<C> {
        Config {
            base_path: "http://podman.io/".to_owned(),
            user_agent: Some("openapi-client-gen".to_owned()),
            client,
        }
    }
}
impl<C: Connector> ClientConfig for Config<C> {
    fn get_base_path(&self) -> &String {
        &self.base_path
    }
    fn get_user_agent(&self) -> &Option<String> {
        &self.user_agent
    }
    fn request<'a>(
        &self,
        request: Request<String>,
    ) -> Pin<Box<dyn Future<Output = Result<Response<Incoming>, HyperError>> + 'a + Send>> {
        Box::pin(self.client.request(request))
    }
}