1 use std::io::Write;
2 use test_programs::proxy;
3 use test_programs::wasi::cli::stderr::get_stderr;
4 use test_programs::wasi::http::types::{
5     Fields, IncomingRequest, OutgoingResponse, ResponseOutparam,
6 };
7 
8 struct T;
9 
10 proxy::export!(T);
11 
12 impl proxy::exports::wasi::http::incoming_handler::Guest for T {
handle(_request: IncomingRequest, outparam: ResponseOutparam)13     fn handle(_request: IncomingRequest, outparam: ResponseOutparam) {
14         print!("this is half a print ");
15         std::io::stdout().flush().unwrap();
16         println!("to stdout");
17         println!(); // empty line
18         println!("after empty");
19 
20         eprint!("this is half a print ");
21         std::io::stderr().flush().unwrap();
22         eprintln!("to stderr");
23         eprintln!(); // empty line
24         eprintln!("after empty");
25 
26         let _ = get_stderr().blocking_write_and_flush(b"start a print ");
27         let _ = get_stderr().blocking_write_and_flush(b"1");
28         let _ = get_stderr().blocking_write_and_flush(b"2");
29         let _ = get_stderr().blocking_write_and_flush(b"3");
30         let _ = get_stderr().blocking_write_and_flush(b"4");
31         let _ = get_stderr().blocking_write_and_flush(b"\n");
32 
33         let resp = OutgoingResponse::new(Fields::new());
34         ResponseOutparam::set(outparam, Ok(resp));
35     }
36 }
37 
main()38 fn main() {}
39