Helper: send an HTTP/1.0 request and return the full response.
(addr: SocketAddr, path: &str)
| 242 | |
| 243 | /// Helper: send an HTTP/1.0 request and return the full response. |
| 244 | fn 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. |
| 254 | fn parse_http_addr(line: &str) -> Result<SocketAddr> { |
no test coverage detected