Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

54 changes: 53 additions & 1 deletion crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ pub const SUPPORTED_WASI_MODULES: &[(&str, &str)] = &[
"experimental-wasi-http",
"enables support for the WASI HTTP APIs (experimental), see https://github.com/WebAssembly/wasi-http",
),
(
"experimental-wasi-http-server",
"enables support for the WASI HTTP APIs (experimental) for web serving, see https://github.com/WebAssembly/wasi-http",
),
];

fn init_file_per_thread_logger(prefix: &'static str) {
Expand Down Expand Up @@ -512,6 +516,7 @@ fn parse_wasi_modules(modules: &str) -> Result<WasiModules> {
"experimental-wasi-nn" => Ok(wasi_modules.wasi_nn = enable),
"experimental-wasi-threads" => Ok(wasi_modules.wasi_threads = enable),
"experimental-wasi-http" => Ok(wasi_modules.wasi_http = enable),
"experimental-wasi-http-server" => Ok(wasi_modules.wasi_http_server = enable),
"default" => bail!("'default' cannot be specified with other WASI modules"),
_ => bail!("unsupported WASI module '{}'", module),
};
Expand Down Expand Up @@ -549,6 +554,9 @@ pub struct WasiModules {

/// Enable the experimental wasi-http implementation
pub wasi_http: bool,

/// Enable the experimental wasi-http-server implementation
pub wasi_http_server: bool,
}

impl Default for WasiModules {
Expand All @@ -559,6 +567,7 @@ impl Default for WasiModules {
wasi_nn: false,
wasi_threads: false,
wasi_http: false,
wasi_http_server: false,
}
}
}
Expand All @@ -572,6 +581,7 @@ impl WasiModules {
wasi_crypto: false,
wasi_threads: false,
wasi_http: false,
wasi_http_server: false,
}
}
}
Expand Down Expand Up @@ -734,6 +744,7 @@ mod test {
wasi_nn: false,
wasi_threads: false,
wasi_http: false,
wasi_http_server: false,
}
);
}
Expand All @@ -748,7 +759,8 @@ mod test {
wasi_crypto: false,
wasi_nn: false,
wasi_threads: false,
wasi_http: false
wasi_http: false,
wasi_http_server: false,
}
);
}
Expand All @@ -768,6 +780,7 @@ mod test {
wasi_nn: true,
wasi_threads: false,
wasi_http: false,
wasi_http_server: false,
}
);
}
Expand All @@ -784,6 +797,45 @@ mod test {
wasi_nn: false,
wasi_threads: false,
wasi_http: false,
wasi_http_server: false,
}
);
}

#[test]
fn test_http_client() {
let options =
CommonOptions::try_parse_from(vec!["foo", "--wasi-modules=experimental-wasi-http"])
.unwrap();
assert_eq!(
options.wasi_modules.unwrap(),
WasiModules {
wasi_common: true,
wasi_crypto: false,
wasi_nn: false,
wasi_threads: false,
wasi_http: true,
wasi_http_server: false,
}
);
}

#[test]
fn test_http_server() {
let options = CommonOptions::try_parse_from(vec![
"foo",
"--wasi-modules=experimental-wasi-http-server",
])
.unwrap();
assert_eq!(
options.wasi_modules.unwrap(),
WasiModules {
wasi_common: true,
wasi_crypto: false,
wasi_nn: false,
wasi_threads: false,
wasi_http: false,
wasi_http_server: true,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/test-programs/tests/wasi-http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn run(name: &str) -> anyhow::Result<()> {
}

wasmtime_wasi::sync::add_to_linker(&mut linker, |cx: &mut Ctx| &mut cx.wasi)?;
wasmtime_wasi_http::add_to_linker(&mut linker, |cx: &mut Ctx| &mut cx.http)?;
wasmtime_wasi_http::add_to_linker(&mut linker, |cx: &mut Ctx| &mut cx.http, false)?;

// Create our wasi context.
let builder = WasiCtxBuilder::new().inherit_stdio().arg(name)?;
Expand Down
3 changes: 2 additions & 1 deletion crates/wasi-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ http = { version = "0.2.9" }
http-body = "1.0.0-rc.2"
http-body-util = "0.1.0-rc.2"
thiserror = { workspace = true }
wasmtime = { workspace = true, features = ['component-model'] }
wasmtime = { workspace = true, features = ['component-model', 'async'] }
wasmtime-wasi = { workspace = true, features = [ 'tokio' ] }

# The `ring` crate, used to implement TLS, does not build on riscv64 or s390x
[target.'cfg(not(any(target_arch = "riscv64", target_arch = "s390x")))'.dependencies]
Expand Down
Loading