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

Function http_response_status

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

Source from the content-addressed store, hash-verified

113}
114
115async fn http_response_status(request: Request<Body>) -> Result<Response<Body>> {
116 let status = if let Some(header_val) = request.headers().get("x-response-status") {
117 header_val
118 .to_str()
119 .context("contents of x-response-status")?
120 .parse::<u16>()
121 .context("u16 value from x-response-status")?
122 } else {
123 500
124 };
125 let mut response = Response::builder().status(status);
126 if status == 302 {
127 response = response.header("Location", "http://localhost/response-status");
128 }
129 Ok(response.body(String::new().into())?)
130}
131
132async fn http_response_fail(_request: Request<Body>) -> Result<Response<Body>> {
133 Err(anyhow::anyhow!("error creating response"))

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected