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

Function main

examples/http_server.rs:10–26  ·  view source on GitHub ↗
(request: Request<Body>)

Source from the content-addressed store, hash-verified

8
9#[wstd::http_server]
10async fn main(request: Request<Body>) -> Result<Response<Body>, Error> {
11 let path = request.uri().path_and_query().unwrap().as_str();
12 println!("serving {path}");
13 match path {
14 "/" => http_home(request).await,
15 "/wait-response" => http_wait_response(request).await,
16 "/wait-body" => http_wait_body(request).await,
17 "/stream-body" => http_stream_body(request).await,
18 "/echo" => http_echo(request).await,
19 "/echo-headers" => http_echo_headers(request).await,
20 "/echo-trailers" => http_echo_trailers(request).await,
21 "/response-status" => http_response_status(request).await,
22 "/response-fail" => http_response_fail(request).await,
23 "/response-body-fail" => http_body_fail(request).await,
24 _ => http_not_found(request).await,
25 }
26}
27
28async fn http_home(_request: Request<Body>) -> Result<Response<Body>> {
29 // To send a single string as the response body, use `Responder::respond`.

Callers

nothing calls this directly

Calls 11

http_homeFunction · 0.85
http_wait_responseFunction · 0.85
http_wait_bodyFunction · 0.85
http_stream_bodyFunction · 0.85
http_echoFunction · 0.85
http_echo_headersFunction · 0.85
http_echo_trailersFunction · 0.85
http_response_statusFunction · 0.85
http_response_failFunction · 0.85
http_body_failFunction · 0.85
http_not_foundFunction · 0.70

Tested by

no test coverage detected