Path: blob/main/crates/test-programs/src/bin/api_proxy_forward_request.rs
1693 views
use test_programs::wasi::http::types::{1Headers, IncomingRequest, OutgoingBody, OutgoingResponse, ResponseOutparam,2};34struct T;56test_programs::proxy::export!(T);78impl test_programs::proxy::exports::wasi::http::incoming_handler::Guest for T {9fn handle(request: IncomingRequest, outparam: ResponseOutparam) {10let res = test_programs::http::request(11request.method(),12request.scheme().unwrap(),13request.authority().unwrap().as_str(),14request.path_with_query().unwrap().as_str(),15None,16None,17None,18None,19None,20)21.unwrap();2223let hdrs = Headers::from_list(&res.headers).unwrap();24let resp = OutgoingResponse::new(hdrs);25resp.set_status_code(res.status).expect("status code");26let body = resp.body().expect("outgoing response");2728ResponseOutparam::set(outparam, Ok(resp));2930let out = body.write().expect("outgoing stream");31out.blocking_write_and_flush(res.body.as_ref())32.expect("writing response");3334drop(out);35OutgoingBody::finish(body, None).expect("outgoing-body.finish");36}37}3839// Technically this should not be here for a proxy, but given the current40// framework for tests it's required since this file is built as a `bin`41fn main() {}424344