1#![forbid(future_incompatible, rust_2018_idioms)]
8#![deny(missing_debug_implementations, nonstandard_style)]
9#![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
10#![cfg_attr(feature = "docs", feature(doc_cfg))]
11#![cfg_attr(
13 not(all(feature = "wasm_client", target_arch = "wasm32")),
14 forbid(unsafe_code)
15)]
16
17mod config;
18pub use config::Config;
19
20#[cfg_attr(feature = "docs", doc(cfg(feature = "curl_client")))]
21#[cfg(all(feature = "curl_client", not(target_arch = "wasm32")))]
22pub mod isahc;
23
24#[cfg_attr(feature = "docs", doc(cfg(feature = "wasm_client")))]
25#[cfg(all(feature = "wasm_client", target_arch = "wasm32"))]
26pub mod wasm;
27
28#[cfg_attr(feature = "docs", doc(cfg(feature = "native_client")))]
29#[cfg(any(feature = "curl_client", feature = "wasm_client"))]
30pub mod native;
31
32#[cfg_attr(feature = "docs", doc(cfg(feature = "h1_client")))]
33#[cfg_attr(feature = "docs", doc(cfg(feature = "default")))]
34#[cfg(any(feature = "h1_client", feature = "h1_client_rustls"))]
35pub mod h1;
36
37#[cfg_attr(feature = "docs", doc(cfg(feature = "hyper_client")))]
38#[cfg(feature = "hyper_client")]
39pub mod hyper;
40
41pub type Request = http_types::Request;
43
44pub type Response = http_types::Response;
46
47pub use async_trait::async_trait;
48pub use http_types;
49
50#[async_trait]
63pub trait HttpClient: std::fmt::Debug + Unpin + Send + Sync + 'static {
64 async fn send(&self, req: Request) -> Result<Response, Error>;
66
67 fn set_config(&mut self, _config: Config) -> http_types::Result<()> {
71 unimplemented!(
72 "{} has not implemented `HttpClient::set_config()`",
73 type_name_of(self)
74 )
75 }
76
77 fn config(&self) -> &Config {
79 unimplemented!(
80 "{} has not implemented `HttpClient::config()`",
81 type_name_of(self)
82 )
83 }
84}
85
86fn type_name_of<T: ?Sized>(_val: &T) -> &'static str {
87 std::any::type_name::<T>()
88}
89
90pub type Body = http_types::Body;
92
93pub type Error = http_types::Error;
95
96#[async_trait]
97impl HttpClient for Box<dyn HttpClient> {
98 async fn send(&self, req: Request) -> http_types::Result<Response> {
99 self.as_ref().send(req).await
100 }
101
102 fn set_config(&mut self, config: Config) -> http_types::Result<()> {
103 self.as_mut().set_config(config)
104 }
105
106 fn config(&self) -> &Config {
107 self.as_ref().config()
108 }
109}