Adding current working progress to hashmap for dynamic routes.
This commit is contained in:
@@ -51,26 +51,12 @@ pub fn handle_connection(mut stream: TcpStream) {
|
||||
);
|
||||
stream.write(response.as_bytes()).unwrap();
|
||||
stream.write(&image_data).unwrap();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
response = return_response(&inc_request.path);
|
||||
stream.write(response.as_bytes()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_header(headers: Vec<String>, needle: &str) -> String {
|
||||
let mut value = String::new();
|
||||
for header in headers {
|
||||
let split_header: Vec<&str> = header.split(":").collect();
|
||||
let header_key: String = split_header.first().expect("Nothing here").to_string();
|
||||
if header_key == needle {
|
||||
value = split_header[1].to_string();
|
||||
}
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
fn return_response(path_or_code: &str) -> String {
|
||||
let status_line: String;
|
||||
let contents: String;
|
||||
@@ -99,3 +85,16 @@ fn return_response(path_or_code: &str) -> String {
|
||||
pub fn path_exists(path: &str) -> bool {
|
||||
fs::metadata(path).is_ok()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn get_header(headers: Vec<String>, needle: &str) -> String {
|
||||
let mut value = String::new();
|
||||
for header in headers {
|
||||
let split_header: Vec<&str> = header.split(":").collect();
|
||||
let header_key: String = split_header.first().expect("Nothing here").to_string();
|
||||
if header_key == needle {
|
||||
value = split_header[1].to_string();
|
||||
}
|
||||
}
|
||||
value
|
||||
}
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
use std::fs;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn get_route_data(route: &str) -> String {
|
||||
match route {
|
||||
// @required - set valid routes here.
|
||||
let route_map = HashMap::from([
|
||||
("/", "./public/index.html"),
|
||||
]);
|
||||
|
||||
dbg!(route_map.get(route));
|
||||
|
||||
// match route_map.get(route) {
|
||||
// None => ,
|
||||
// Some(page) => Some(page),
|
||||
// };
|
||||
// Some("test".to_string())
|
||||
//
|
||||
//
|
||||
// High leve list of thigns to do
|
||||
// 1. get the correct file to retrieve
|
||||
// 2. parse the file and swap out any dynamic sections
|
||||
// 3. return the string based response.
|
||||
let route_file: String = match route {
|
||||
"/" => {
|
||||
"
|
||||
return fs::read_to_string("./public/index.html").unwrap();
|
||||
},
|
||||
"/about" => {
|
||||
@@ -17,6 +37,8 @@ pub fn get_route_data(route: &str) -> String {
|
||||
return fs::read_to_string("./public/404.html").unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// fs::read_to_string(route_file).unwrap();
|
||||
}
|
||||
|
||||
// pub fn path_exists(path: &str) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user