use std::io::{Write}; use std::string; use std::net::{TcpListener, TcpStream}; fn serve(mut stream: TcpStream) { let contents = "

herb works!

"; let response = format!("{}{}", "HTTP/1.1 200 OK\r\n\r\n", contents); stream.write(response.as_bytes()).unwrap(); stream.flush().unwrap(); } fn main() -> std::io::Result<()> { let listen = TcpListener::bind("127.0.0.1:8080")?; for stream in listen.incoming() { serve(stream?); } Ok(()) }