2021-08-29 16:07:05 +01:00
|
|
|
use std::io::{Write};
|
|
|
|
use std::string;
|
|
|
|
use std::net::{TcpListener, TcpStream};
|
|
|
|
|
|
|
|
fn serve(mut stream: TcpStream) {
|
|
|
|
let contents = "<h1>herb works!</h1>";
|
|
|
|
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(())
|
2021-08-29 15:18:20 +01:00
|
|
|
}
|