Skip to content

Commit

Permalink
Introduce a WebHttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Aug 10, 2023
1 parent 4821a56 commit 498fce9
Show file tree
Hide file tree
Showing 10 changed files with 325 additions and 21 deletions.
21 changes: 12 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/wasi-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bitflags = "1.3.0"
cfg-if = "1.0.0"
anyhow = "1.0.66"
byteorder = "1.3"
time = "0.2"
time = "0.3"
tracing = { version = "0.1.37" }

[dev-dependencies.pretty_assertions]
Expand Down
8 changes: 6 additions & 2 deletions lib/wasix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ url = "2.3.1"
petgraph = "0.6.3"
rayon = { version = "1.7.0", optional = true }
wasm-bindgen = { version = "0.2.87", optional = true }
js-sys = { version = "0.3.64", optional = true }
wasm-bindgen-futures = { version = "0.4.37", optional = true }
web-sys = { version = "0.3.64", features = ["Request", "RequestInit", "Window", "WorkerGlobalScope", "RequestMode", "Response", "Headers"], optional = true }

[target.'cfg(not(target_arch = "riscv64"))'.dependencies.reqwest]
version = "0.11"
Expand All @@ -94,6 +97,7 @@ winapi = "0.3"
wasmer = { path = "../api", version = "=4.1.0", default-features = false, features = ["wat", "js-serializable-module"] }
tokio = { version = "1", features = [ "sync", "macros", "rt" ], default_features = false }
pretty_assertions = "1.3.0"
wasm-bindgen-test = "0.3.0"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.0"
Expand All @@ -111,15 +115,15 @@ time = ["tokio/time"]
webc_runner_rt_wcgi = ["hyper", "wcgi", "wcgi-host", "tower", "tower-http"]
webc_runner_rt_emscripten = ["wasmer-emscripten"]

sys = ["webc/mmap", "time"]
sys = ["webc/mmap", "time", "virtual-mio/sys"]
sys-default = ["sys", "logging", "host-fs", "sys-poll", "sys-thread", "host-vnet", "host-threads", "host-reqwest"]
sys-poll = []
sys-thread = ["tokio/rt", "tokio/time", "tokio/rt-multi-thread", "rayon"]

# Deprecated. Kept it for compatibility
compiler = []

js = ["virtual-fs/no-time", "getrandom/js", "chrono"]
js = ["virtual-fs/no-time", "getrandom/js", "chrono", "js-sys", "wasm-bindgen", "wasm-bindgen-futures", "web-sys"]
js-default = ["js"]
test-js = ["js", "wasmer/wat"]

Expand Down
1 change: 0 additions & 1 deletion lib/wasix/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ impl From<http::Request<()>> for HttpRequest {
}
}


// TODO: use types from http crate?
pub struct HttpResponse {
pub body: Option<Vec<u8>>,
Expand Down
7 changes: 6 additions & 1 deletion lib/wasix/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pub mod client_impl;
#[cfg(feature = "host-reqwest")]
pub mod reqwest;

pub use self::client::*;
#[cfg(feature = "js")]
mod web_http_client;

pub use self::{client::*, web_http_client::WebHttpClient};

pub(crate) const USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "-", env!("CARGO_PKG_VERSION"));

Expand All @@ -13,6 +16,8 @@ pub fn default_http_client() -> Option<impl HttpClient + Send + Sync + 'static>
cfg_if::cfg_if! {
if #[cfg(feature = "host-reqwest")] {
Some(self::reqwest::ReqwestHttpClient::default())
} else if #[cfg(feature = "js")] {
Some(web_http_client::WebHttpClient::default())
} else {
// Note: We need something to use with turbofish otherwise returning
// a plain None will complain about not being able to infer the "T"
Expand Down
Loading

0 comments on commit 498fce9

Please sign in to comment.