1 use anyhow::Context;
2 use std::io::{self, Read};
3 use test_programs::wasi::http::types::{Method, Scheme};
4
main()5 fn main() {
6 // Make sure the final body is larger than 1024*1024, but we cannot allocate
7 // so much memory directly in the wasm program, so we use the `repeat`
8 // method to increase the body size.
9 const LEN: usize = 1024;
10 const REPEAT: usize = 1025;
11 let mut buffer = [0; LEN];
12 let addr = std::env::var("HTTP_SERVER").unwrap();
13 io::repeat(0b001).read_exact(&mut buffer).unwrap();
14 let res = test_programs::http::request(
15 Method::Post,
16 Scheme::Http,
17 &addr,
18 "/post",
19 Some(&buffer.repeat(REPEAT)),
20 None,
21 None,
22 None,
23 None,
24 )
25 .context("/post large")
26 .unwrap();
27
28 println!("/post large: {}", res.status);
29 assert_eq!(res.status, 200);
30 let method = res.header("x-wasmtime-test-method").unwrap();
31 assert_eq!(std::str::from_utf8(method).unwrap(), "POST");
32 assert_eq!(res.body.len(), LEN * REPEAT);
33 }
34