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