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
use std::collections::HashMap;
#[cfg(not(target_arch = "wasm32"))]
use std::convert::TryFrom;
use serde::{Deserialize, Serialize};
#[cfg(not(target_arch = "wasm32"))]
use crate::GraphQLError;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ClientConfig {
pub endpoint: String,
pub timeout: Option<u64>,
pub headers: Option<HashMap<String, String>>,
pub proxy: Option<GQLProxy>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ProxyType {
Http,
Https,
All,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ProxyAuth {
pub username: String,
pub password: String,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GQLProxy {
pub schema: String,
pub type_: ProxyType,
pub auth: Option<ProxyAuth>,
}
#[cfg(not(target_arch = "wasm32"))]
impl TryFrom<GQLProxy> for reqwest::Proxy {
type Error = GraphQLError;
fn try_from(gql_proxy: GQLProxy) -> Result<Self, Self::Error> {
let proxy = match gql_proxy.type_ {
ProxyType::Http => reqwest::Proxy::http(gql_proxy.schema),
ProxyType::Https => reqwest::Proxy::https(gql_proxy.schema),
ProxyType::All => reqwest::Proxy::all(gql_proxy.schema),
}
.map_err(|e| Self::Error::with_text(format!("{:?}", e)))?;
Ok(proxy)
}
}