Add Getting files from the server
Change-Id: I7b81d4d455af81a8489bfb38223e19901b6c1c60
Reviewed-on: https://git.clicks.codes/c/Clicks/BYO/HttpServer/rust/+/264
Tested-by: Skyler Grey <minion@clicks.codes>
Reviewed-by: Samuel Shuert <coded@clicks.codes>
diff --git a/files/Horsey_scooby_237_donkey b/files/Horsey_scooby_237_donkey
new file mode 100644
index 0000000..e140755
--- /dev/null
+++ b/files/Horsey_scooby_237_donkey
@@ -0,0 +1 @@
+SDfo;iuw4njkl 90u43 nd fopjnsf pd j4nlsrfvu094ujnedfu0-9u
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 7d56bcb..6e98efa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,7 +14,6 @@
async fn process_socket(mut stream: TcpStream) -> Result<(), &'static str> {
println!("accepted new connection");
-
let mut request: HashMap<String, String> = HashMap::new();
let mut line_num: usize = 0;
loop {
@@ -73,8 +72,9 @@
"files" => {
let file_name = path.join("/");
let args: Vec<String> = args().collect();
- let file_path = if &args[1] == "directory" {
- args[2].to_owned() + file_name.as_str()
+ let dir_arg = args.iter().find_position(|item| **item == "--directory");
+ let file_path = if dir_arg.is_some() {
+ args[dir_arg.unwrap().0+1].to_owned() + "/" + file_name.as_str()
} else {
return Err("No directory Given".into())
};