Add some checks

This commit is contained in:
g1n 2021-07-09 06:08:50 +00:00
parent ebdd92c64c
commit c8539f78a1
2 changed files with 35 additions and 7 deletions

1
index.gmi Normal file
View File

@ -0,0 +1 @@
Hello, World!

View File

@ -17,14 +17,41 @@ fn handle_connection(mut stream: TcpStream) {
stream.read(&mut buffer).unwrap();
let contents = fs::read_to_string("index.gmi").unwrap();
let response = format!(
"2 text/gemini\r\n{}",
contents
);
let hostname = "localhost";
let path = "/";
let post = "\r\n";
/*
let get = format!(
"{} {} {} {}",
hostname,
path,
post.len(),
post
);*/
let get = b"127.0.0.1 / 0\r\n";
if buffer.starts_with(get) {
let contents = fs::read_to_string("index.gmi").unwrap();
let status = 2;
let meta = "text/gemini";
let response = format!(
"{} {}\r\n{}",
status,
meta,
contents
);
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
} else {
let status_line = "4 Not Found";
stream.write(status_line.as_bytes()).unwrap();
stream.flush().unwrap();
}
stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap();
}