wasmer_wasix/http/
mod.rs

1mod client;
2
3#[cfg(feature = "host-reqwest")]
4pub mod reqwest;
5
6#[cfg(feature = "js")]
7mod web_http_client;
8
9#[cfg(feature = "js")]
10pub use self::web_http_client::WebHttpClient;
11
12pub use self::client::*;
13
14pub(crate) const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "-", env!("CARGO_PKG_VERSION"));
15
16/// Try to instantiate a HTTP client that is suitable for the current platform.
17pub fn default_http_client() -> Option<impl HttpClient + Send + Sync + 'static> {
18    cfg_if::cfg_if! {
19        if #[cfg(feature = "host-reqwest")] {
20            Some(self::reqwest::ReqwestHttpClient::default())
21        } else if #[cfg(feature = "js")] {
22            Some(web_http_client::WebHttpClient::default())
23        } else {
24            // Note: We need something to use with turbofish otherwise returning
25            // a plain None will complain about not being able to infer the "T"
26            // in Option<T>
27            #[derive(Debug)]
28            enum Unimplemented {}
29            impl HttpClient for Unimplemented {
30                fn request(&self, _request: HttpRequest) -> futures::future::BoxFuture<'_, Result<HttpResponse, anyhow::Error>> {
31                    match *self {}
32                }
33            }
34
35            Option::<Unimplemented>::None
36        }
37    }
38}