From 37f61346825f15a1d85c6b415023360701e78b67 Mon Sep 17 00:00:00 2001 From: silverwizard Date: Fri, 3 Feb 2023 23:36:04 -0500 Subject: [PATCH] Got shock to milestone 0 --- index.md | 24 ------------------------ src/main.rs | 25 ++++++++++++++----------- 2 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 index.md diff --git a/index.md b/index.md deleted file mode 100644 index c483de7..0000000 --- a/index.md +++ /dev/null @@ -1,24 +0,0 @@ -# Obscuritus - -Hello! - -I hope you're not looking for anything too cool here - as this is mostly my musing regarding RPGs, Sysadminning, or homegames. The more I end up doing, the happier I'll be - at some point I'll do more of this. - -If you're looking for old issues of the [Obscuritus](RPGs/Obscuritus_Mag.html) magazine I printed for my ancient Dresden Files game - I still have them, at that link. - -If you're looking for things I've made for print: -I've currently got nothing to put out - hopefully will change - -If you're interested - my [h-card](https://indieweb.org/h-card) is: -

- -
- http://obscuritus.ca -
- - silverwizard@obscuritus.ca -
- xmpp:silverwizard@obscuritus.ca -
- http://convenient.email/profile/silverwizard?tab=profile -

diff --git a/src/main.rs b/src/main.rs index f333a33..7482b93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,27 +23,30 @@ fn handle_connection(mut stream: TcpStream) { let buf_reader = BufReader::new(&mut stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let mut content = "Error 404

Not Found

"; - let mut page; let mut status_line = "HTTP/1.1 404 NOT FOUND"; let end = request_line.len()-9; let keyword = &request_line[0..3]; - let path = &request_line[5..end]; + let mut path = &request_line[5..end]; let version = &request_line[(end+1)..request_line.len()]; - println!("Line length: {}{}{}", keyword, path, version); + let page: rust_embed::EmbeddedFile; if keyword == "GET" { - if version == "HTTP/1.1" { - if path == "index.html" || path == "" { - status_line = "HTTP/1.1 200 OK"; - page = Asset::get("index.html").unwrap(); - content = std::str::from_utf8(page.data.as_ref()).unwrap(); - }else if path == "style.css" { + if version == "HTTP/1.1" || version == "HTTP/2.0" || version == "HTTP/1.0" { + if path == "" { + path = "index.html"; + } + if Asset::iter().any(|x| x.as_ref().eq(path)) { + page = Asset::get(path).unwrap(); status_line = "HTTP/1.1 200 OK"; - page = Asset::get("style.css").unwrap(); content = std::str::from_utf8(page.data.as_ref()).unwrap(); } + }else{ + status_line = "HTTP/1.1 505 NOT IMPLEMENTED"; + content = "Error 505

HTTP Version Not Supported

"; } + }else{ + status_line = "HTTP/1.1 501 Not Implemented"; + content = "Error 501

Not Implemented

"; } - let status_line = "HTTP/1.1 200 OK"; let length = content.len(); let response = format!( "{}\r\nContent-Length: {}\r\n\r\n{}"