Add path handling
This commit is contained in:
parent
9e478116f8
commit
d5b412aef8
22
src/main.rs
22
src/main.rs
|
@ -11,6 +11,7 @@ fn main() {
|
|||
let mut verbose = false;
|
||||
let mut host = "localhost".to_string();
|
||||
let mut port = 3000; // TODO: change to 300
|
||||
//let mut root_dir = format!("/home/{}/public_spartan/", "username");
|
||||
// Arguments
|
||||
{
|
||||
let mut ap = ArgumentParser::new();
|
||||
|
@ -24,6 +25,9 @@ fn main() {
|
|||
ap.refer(&mut port)
|
||||
.add_option(&["-p", "--port"], Store,
|
||||
"Port");
|
||||
/*ap.refer(&mut root_dir)
|
||||
.add_option(&["-d", "--root-dir"], Store,
|
||||
"Root directory");*/
|
||||
ap.parse_args_or_exit();
|
||||
}
|
||||
if verbose {
|
||||
|
@ -57,7 +61,8 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
_post
|
||||
);*/
|
||||
|
||||
let _echo = b"$hostname /echo 0\r\n"; // TODO: fix echo behaviour
|
||||
// let _echo = b"$hostname /echo 0\r\n"; // TODO: fix echo behaviour
|
||||
|
||||
let request = String::from_utf8_lossy(&buffer[..]);
|
||||
let parsed_request: Vec<&str> = request.split(' ').collect();
|
||||
|
||||
|
@ -76,24 +81,21 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
let get = format!( "{} {} {}\r\n {}\r\n", host, _path, _post_len, _post);
|
||||
let get_bytes = get.as_bytes();
|
||||
|
||||
let status_line = "2 text/gemini\r\n";
|
||||
|
||||
/*
|
||||
let (status_line, _filename) = if buffer.starts_with(get_bytes) {
|
||||
("2 text/gemini\r\n", "index.gmi")
|
||||
let (status_line, _filename) = if _path == "/" {
|
||||
("2 text/gemini", format!(".{}index.gmi", _path))
|
||||
} else {
|
||||
("4 Not found\r\n", "") // TODO: fix Not Found behaviour
|
||||
("4 Not found", format!(".{}error.gmi", "/")) // TODO: fix Not Found behaviour
|
||||
};
|
||||
*/
|
||||
|
||||
//let filename = "index.gmi";
|
||||
/*
|
||||
let _contents = "";
|
||||
if _filename != "" {
|
||||
let _contents = fs::read_to_string(_filename).unwrap();
|
||||
} else { */
|
||||
let _contents = fs::read_to_string("index.gmi").unwrap();
|
||||
let _contents = fs::read_to_string(_filename).unwrap();
|
||||
let response = format!(
|
||||
"{}\r\n{}\r\n",
|
||||
"{}\r\n {}",
|
||||
status_line,
|
||||
_contents
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue