1 use anyhow::Context;
2 use std::io::{self, Read};
3 use test_programs::p3::wasi::http::types::{Method, Scheme};
4 
5 struct Component;
6 
7 test_programs::p3::export!(Component);
8 
9 impl test_programs::p3::exports::wasi::cli::run::Guest for Component {
run() -> Result<(), ()>10     async fn run() -> Result<(), ()> {
11         // Make sure the final body is larger than 1024*1024, but we cannot allocate
12         // so much memory directly in the wasm program, so we use the `repeat`
13         // method to increase the body size.
14         const LEN: usize = 1024;
15         const REPEAT: usize = 1025;
16         let mut buffer = [0; LEN];
17         let addr = test_programs::p3::wasi::cli::environment::get_environment()
18             .into_iter()
19             .find_map(|(k, v)| k.eq("HTTP_SERVER").then_some(v))
20             .unwrap();
21         io::repeat(0b001).read_exact(&mut buffer).unwrap();
22         let res = test_programs::p3::http::request(
23             Method::Post,
24             Scheme::Http,
25             &addr,
26             "/post",
27             Some(&buffer.repeat(REPEAT)),
28             None,
29             None,
30             None,
31             None,
32         )
33         .await
34         .context("/post large")
35         .unwrap();
36 
37         println!("/post large: {}", res.status);
38         assert_eq!(res.status, 200);
39         let method = res.header("x-wasmtime-test-method").unwrap();
40         assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
41         assert_eq!(res.body.len(), LEN * REPEAT);
42         Ok(())
43     }
44 }
45 
main()46 fn main() {}
47