1*b315a0a8SYosh use test_programs::wasi::http::types::{
2*b315a0a8SYosh Headers, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam,
3*b315a0a8SYosh };
4*b315a0a8SYosh
5*b315a0a8SYosh struct T;
6*b315a0a8SYosh
7*b315a0a8SYosh test_programs::proxy::export!(T);
8*b315a0a8SYosh
9*b315a0a8SYosh impl test_programs::proxy::exports::wasi::http::incoming_handler::Guest for T {
handle(request: IncomingRequest, outparam: ResponseOutparam)10*b315a0a8SYosh fn handle(request: IncomingRequest, outparam: ResponseOutparam) {
11*b315a0a8SYosh let res = test_programs::http::request(
12*b315a0a8SYosh request.method(),
13*b315a0a8SYosh request.scheme().unwrap(),
14*b315a0a8SYosh request.authority().unwrap().as_str(),
15*b315a0a8SYosh request.path_with_query().unwrap().as_str(),
16*b315a0a8SYosh None,
17*b315a0a8SYosh None,
18*b315a0a8SYosh None,
19*b315a0a8SYosh None,
20*b315a0a8SYosh None,
21*b315a0a8SYosh )
22*b315a0a8SYosh .unwrap();
23*b315a0a8SYosh
24*b315a0a8SYosh let hdrs = Headers::from_list(&res.headers).unwrap();
25*b315a0a8SYosh let resp = OutgoingResponse::new(hdrs);
26*b315a0a8SYosh resp.set_status_code(res.status).expect("status code");
27*b315a0a8SYosh let body = resp.body().expect("outgoing response");
28*b315a0a8SYosh
29*b315a0a8SYosh ResponseOutparam::set(outparam, Ok(resp));
30*b315a0a8SYosh
31*b315a0a8SYosh let out = body.write().expect("outgoing stream");
32*b315a0a8SYosh out.blocking_write_and_flush(res.body.as_ref())
33*b315a0a8SYosh .expect("writing response");
34*b315a0a8SYosh
35*b315a0a8SYosh drop(out);
36*b315a0a8SYosh OutgoingBody::finish(body, None).expect("outgoing-body.finish");
37*b315a0a8SYosh }
38*b315a0a8SYosh }
39*b315a0a8SYosh
40*b315a0a8SYosh // Technically this should not be here for a proxy, but given the current
41*b315a0a8SYosh // framework for tests it's required since this file is built as a `bin`
main()42*b315a0a8SYosh fn main() {}
43