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

Function main

tests/http_first_byte_timeout.rs:4–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3#[wstd::main]
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Set first byte timeout to 1/2 second.
6 let mut client = Client::new();
7 client.set_first_byte_timeout(std::time::Duration::from_millis(500));
8 // This get request will connect to the server, which will then wait 1 second before
9 // returning a response.
10 let request = Request::get("https://postman-echo.com/delay/1").body(Body::empty())?;
11 let result = client.send(request).await;
12
13 assert!(result.is_err(), "response should be an error");
14 let error = result.unwrap_err();
15 assert!(
16 matches!(
17 error.downcast_ref::<ErrorCode>(),
18 Some(ErrorCode::ConnectionReadTimeout)
19 ),
20 "expected ConnectionReadTimeout error, got: {error:?>}"
21 );
22
23 Ok(())
24}

Callers

nothing calls this directly

Calls 4

getFunction · 0.85
emptyFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected