Decorate index page.
This commit is contained in:
parent
9f28bcdb84
commit
60af42f3fa
3 changed files with 7 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,4 +4,4 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -25,7 +25,7 @@ fn process_cgi(filename: String) -> String {
|
||||||
|
|
||||||
let output = Command::new(script)
|
let output = Command::new(script)
|
||||||
.arg("GATEWAY_INTERFACE=\"CGI/1.1\"")
|
.arg("GATEWAY_INTERFACE=\"CGI/1.1\"")
|
||||||
.arg("SERVER_SOFTWARE=\"Herb/0.3.0\"")
|
.arg("SERVER_SOFTWARE=\"Herb/0.3.1\"")
|
||||||
.arg("REQUEST_METHOD=\"GET\"")
|
.arg("REQUEST_METHOD=\"GET\"")
|
||||||
.arg(format!("QUERY_STRING=\"{}\"", query))
|
.arg(format!("QUERY_STRING=\"{}\"", query))
|
||||||
.arg(format!("SCRIPT_NAME=\"{}\"", script))
|
.arg(format!("SCRIPT_NAME=\"{}\"", script))
|
||||||
|
@ -110,14 +110,12 @@ fn check_if_dir(directory: String) -> bool {
|
||||||
|
|
||||||
fn generate_index(directory: String) -> String {
|
fn generate_index(directory: String) -> String {
|
||||||
|
|
||||||
let mut index = format!("<!DOCTYPE HTML><html><body><h1>Directory of {}</h1>", directory);
|
let mut index = format!("<!DOCTYPE HTML><html><body><h1>Directory of {}</h1><hr/>", directory);
|
||||||
for file in fs::read_dir(directory).unwrap() {
|
for file in fs::read_dir(directory).unwrap() {
|
||||||
|
index = format!("{}<br/><a href={}>{:#?}</a>", index, format!("\"./{}\"", file.as_ref().unwrap().path().display().to_string()), file.unwrap().file_name());
|
||||||
index = format!("{}<br/><a href={}>{:#?}</a>", index, file.as_ref().unwrap().path().display(), file.unwrap().file_name());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return index.to_string();
|
return format!("{}<hr/>Generated by herb 0.3.1", index).to_string();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +242,6 @@ fn serve(mut stream: TcpStream) {
|
||||||
.read_until(b'\n', &mut request)
|
.read_until(b'\n', &mut request)
|
||||||
.expect("Failed to read from stream!");
|
.expect("Failed to read from stream!");
|
||||||
|
|
||||||
|
|
||||||
let resource = process_request(request);
|
let resource = process_request(request);
|
||||||
|
|
||||||
// Haha, bodged my way around Rust's ownership paradigm!
|
// Haha, bodged my way around Rust's ownership paradigm!
|
||||||
|
@ -258,7 +255,7 @@ fn serve(mut stream: TcpStream) {
|
||||||
let contents = get_page(resource);
|
let contents = get_page(resource);
|
||||||
let header = "HTTP/1.1 200 OK\r\n";
|
let header = "HTTP/1.1 200 OK\r\n";
|
||||||
let content_type = format!("Content-Type: {}\r\n", mime);
|
let content_type = format!("Content-Type: {}\r\n", mime);
|
||||||
let server = "Server: Herb/0.3.0\r\n";
|
let server = "Server: Herb/0.3.1\r\n";
|
||||||
let extra_fields;
|
let extra_fields;
|
||||||
|
|
||||||
if cfg!(unix) {
|
if cfg!(unix) {
|
||||||
|
|
Loading…
Reference in a new issue