Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

run: honour the --http-outgoing-body-* options (#14440)

Xia Chao0a81d246973f
diff --git a/crates/test-programs/src/bin/p2_cli_run_outgoing_body_chunk_size.rs b/crates/test-programs/src/bin/p2_cli_run_outgoing_body_chunk_size.rs
new file mode 100644
index 0000000000..b2ac41830b
--- /dev/null
+++ b/crates/test-programs/src/bin/p2_cli_run_outgoing_body_chunk_size.rs
@@ -0,0 +1,25 @@
+//! Prints the number of bytes a single write to an outgoing request body may
+//! carry, which is what the `--http-outgoing-body-chunk-size` option sets.
+//!
+//! Nothing here talks to the network: the body is built and then read back
+//! through `check_write`, so the printed number is the configured budget.
+use test_programs::wasi::http::types::{Headers, Method, OutgoingRequest, Scheme};
+
+fn main() {
+ let request = OutgoingRequest::new(Headers::new());
+ request
+ .set_method(&Method::Post)
+ .expect("failed to set method");
+ request
+ .set_scheme(Some(&Scheme::Http))
+ .expect("failed to set scheme");
+ request
+ .set_authority(Some("localhost"))
+ .expect("failed to set authority");
+ request
+ .set_path_with_query(Some("/"))
+ .expect("failed to set path_with_query");
+ let body = request.body().expect("failed to get outgoing body");
+ let stream = body.write().expect("failed to get output stream");
+ println!("{}", stream.check_write().expect("check_write failed"));
+}
diff --git a/src/commands/run.rs b/src/commands/run.rs
index d896dc60b0..aa0d41e8b1 100644
--- a/src/commands/run.rs
+++ b/src/commands/run.rs
@@ -1291,6 +1291,11 @@ impl RunCommand {
}
let http = self.run.wasi_http_ctx()?;
store.data_mut().wasi_http = Some(http);
+ // The hooks carry the `--http-outgoing-body-*` limits, so they
+ // have to be taken from the CLI options as well: `Host` is
+ // built with `Host::default()`, which leaves the default hooks
+ // in place.
+ store.data_mut().wasi_http_hooks = self.run.wasi_http_hooks();
}
}
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index c9a139d642..92de02f629 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -1782,6 +1782,29 @@ mod test_programs {
Ok(())
}
+ #[test]
+ fn p2_cli_run_outgoing_body_chunk_size() -> Result<()> {
+ // Without the option an outgoing body keeps its 1 MiB default budget.
+ let stdout = run_wasmtime(&[
+ "run",
+ "-Shttp=y",
+ P2_CLI_RUN_OUTGOING_BODY_CHUNK_SIZE_COMPONENT,
+ ])?;
+ assert_eq!(stdout.trim(), "1048576");
+
+ // `-Shttp-outgoing-body-chunk-size` is what changes that budget, and
+ // `wasmtime run` has to honour it just like `wasmtime serve` does.
+ let stdout = run_wasmtime(&[
+ "run",
+ "-Shttp=y",
+ "-Shttp-outgoing-body-chunk-size=1024",
+ P2_CLI_RUN_OUTGOING_BODY_CHUNK_SIZE_COMPONENT,
+ ])?;
+ assert_eq!(stdout.trim(), "1024");
+
+ Ok(())
+ }
+
#[tokio::test]
#[ignore] // TODO: printing stderr in the child and killing the child at the
// end of this test race so the stderr may be present or not. Need