Add Getting files from the server
Change-Id: I713348042ae245b30e3bcd4a80a42b43a12a2e98
Reviewed-on: https://git.clicks.codes/c/Clicks/BYO/HttpServer/rust/+/263
Tested-by: Skyler Grey <minion@clicks.codes>
Reviewed-by: Samuel Shuert <coded@clicks.codes>
diff --git a/src/main.rs b/src/main.rs
index 90cc586..7d56bcb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,6 +6,7 @@
use itertools::Itertools;
use nom::AsChar;
+#[derive(Debug)]
enum BodyTypes {
File(File),
String(String)
@@ -46,16 +47,12 @@
line_num += 1;
}
- // println!("{:?}", request);
-
let mut path = request.get("path").unwrap().split("/");
let response_status: String;
let mut response_headers: Vec<String> = vec![];
let response_body: BodyTypes;
- // println!("{:?}", path);
-
path.next().unwrap();
match path.next().unwrap() {
@@ -87,6 +84,7 @@
Ok(file) => {
response_status = "200 OK".into();
response_body = BodyTypes::File(file);
+ response_headers.push("Content-Type: application/octet-stream".into());
},
Err(_) => {
response_status = "404 Not Found".into();
@@ -100,6 +98,8 @@
}
}
+ println!("{:?}", response_body);
+
match response_body {
BodyTypes::String(ref content) => {
if content.len() > 0 {