|
|
@@ -1,6 +1,6 @@ |
|
|
|
use std::net::{TcpStream, TcpListener}; |
|
|
|
use std::io::prelude::*; |
|
|
|
|
|
|
|
use std::fs; |
|
|
|
|
|
|
|
fn main() { |
|
|
|
let listener = TcpListener::bind("127.0.0.1:26382").unwrap(); |
|
|
@@ -14,14 +14,22 @@ fn main() { |
|
|
|
|
|
|
|
fn handle_connecton(mut stream: TcpStream) { |
|
|
|
let mut buffer = [0; 512]; |
|
|
|
|
|
|
|
stream.read(&mut buffer).unwrap(); |
|
|
|
|
|
|
|
let contents = fs::read_to_string("hello.html").unwrap(); |
|
|
|
let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents); |
|
|
|
stream.write(response.as_bytes()).unwrap(); |
|
|
|
let get = "GET / HTTP/1.1\r\n"; |
|
|
|
|
|
|
|
if buffer.starts_with(get) { |
|
|
|
// It's the request we want |
|
|
|
let contents = fs::read_to_string("hello.html").unwrap(); |
|
|
|
let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents); |
|
|
|
stream.write(response.as_bytes()).unwrap(); |
|
|
|
|
|
|
|
stream.flush().unwrap(); |
|
|
|
} else { |
|
|
|
// a different request so who cares |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stream.flush().unwrap(); |
|
|
|
|
|
|
|
// println!("Request: {}", String::from_utf8_lossy(&buffer[..])); |
|
|
|
} |