MCPcopy Create free account
hub / github.com/bytecodealliance/wstd / main

Function main

examples/http_server_proxy.rs:13–32  ·  view source on GitHub ↗
(server_req: Request<Body>)

Source from the content-addressed store, hash-verified

11
12#[wstd::http_server]
13async fn main(server_req: Request<Body>) -> Result<Response<Body>, Error> {
14 match server_req.uri().path_and_query().unwrap().as_str() {
15 api_prefixed_path if api_prefixed_path.starts_with(PROXY_PREFIX) => {
16 // Remove PROXY_PREFIX
17 let target_url =
18 std::env::var("TARGET_URL").expect("missing environment variable TARGET_URL");
19 let target_url: Uri = format!(
20 "{target_url}{}",
21 api_prefixed_path
22 .strip_prefix(PROXY_PREFIX)
23 .expect("checked above")
24 )
25 .parse()
26 .expect("final target url should be parseable");
27 println!("Proxying to {target_url}");
28 proxy(server_req, target_url).await
29 }
30 _ => Ok(http_not_found(server_req)),
31 }
32}
33
34async fn proxy(server_req: Request<Body>, target_url: Uri) -> Result<Response<Body>, Error> {
35 let client = Client::new();

Callers

nothing calls this directly

Calls 2

proxyFunction · 0.85
http_not_foundFunction · 0.70

Tested by

no test coverage detected