MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / http_request

Function http_request

tests/all/guest_debug/mod.rs:244–251  ·  view source on GitHub ↗

Helper: send an HTTP/1.0 request and return the full response.

(addr: SocketAddr, path: &str)

Source from the content-addressed store, hash-verified

242
243/// Helper: send an HTTP/1.0 request and return the full response.
244fn http_request(addr: SocketAddr, path: &str) -> Result<String> {
245 let mut tcp = TcpStream::connect_timeout(&addr, Duration::from_secs(5))?;
246 tcp.set_read_timeout(Some(Duration::from_secs(5)))?;
247 write!(tcp, "GET {path} HTTP/1.0\r\nHost: localhost\r\n\r\n")?;
248 let mut response = String::new();
249 let _ = std::io::Read::read_to_string(&mut tcp, &mut response);
250 Ok(response)
251}
252
253/// Parse an HTTP serve address from a "Serving HTTP on http://addr/" line.
254fn parse_http_addr(line: &str) -> Result<SocketAddr> {

Callers 2

Calls 3

read_to_stringFunction · 0.85
OkFunction · 0.85
newFunction · 0.50

Tested by

no test coverage detected