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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#![forbid(future_incompatible, rust_2018_idioms)]
#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![cfg_attr(
not(all(feature = "wasm_client", target_arch = "wasm32")),
forbid(unsafe_code)
)]
mod config;
pub use config::Config;
#[cfg_attr(feature = "docs", doc(cfg(feature = "curl_client")))]
#[cfg(all(feature = "curl_client", not(target_arch = "wasm32")))]
pub mod isahc;
#[cfg_attr(feature = "docs", doc(cfg(feature = "wasm_client")))]
#[cfg(all(feature = "wasm_client", target_arch = "wasm32"))]
pub mod wasm;
#[cfg_attr(feature = "docs", doc(cfg(feature = "native_client")))]
#[cfg(any(feature = "curl_client", feature = "wasm_client"))]
pub mod native;
#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
#[cfg_attr(feature = "docs", doc(cfg(feature = "default")))]
#[cfg(any(feature = "h1_client", feature = "h1_client_rustls"))]
pub mod h1;
#[cfg_attr(feature = "docs", doc(cfg(feature = "hyper_client")))]
#[cfg(feature = "hyper_client")]
pub mod hyper;
pub type Request = http_types::Request;
pub type Response = http_types::Response;
pub use async_trait::async_trait;
pub use http_types;
#[async_trait]
pub trait HttpClient: std::fmt::Debug + Unpin + Send + Sync + 'static {
async fn send(&self, req: Request) -> Result<Response, Error>;
fn set_config(&mut self, _config: Config) -> http_types::Result<()> {
unimplemented!(
"{} has not implemented `HttpClient::set_config()`",
type_name_of(self)
)
}
fn config(&self) -> &Config {
unimplemented!(
"{} has not implemented `HttpClient::config()`",
type_name_of(self)
)
}
}
fn type_name_of<T: ?Sized>(_val: &T) -> &'static str {
std::any::type_name::<T>()
}
pub type Body = http_types::Body;
pub type Error = http_types::Error;
#[async_trait]
impl HttpClient for Box<dyn HttpClient> {
async fn send(&self, req: Request) -> http_types::Result<Response> {
self.as_ref().send(req).await
}
fn set_config(&mut self, config: Config) -> http_types::Result<()> {
self.as_mut().set_config(config)
}
fn config(&self) -> &Config {
self.as_ref().config()
}
}