Fix CGI implementation

This commit is contained in:
abbie 2022-08-28 10:42:32 +01:00
parent 5e783bcbb6
commit 2823990ec8
No known key found for this signature in database
GPG key ID: A575D2415E5E5B6D
3 changed files with 11 additions and 10 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]]
name = "herb"
version = "0.3.1"
version = "0.4.0"

View file

@ -1,6 +1,6 @@
[package]
name = "herb"
version = "0.3.1"
version = "0.4.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -21,14 +21,15 @@ fn process_cgi(filename: String) -> String {
query = "";
script = &filename;
}
println!("{}", script);
let output = Command::new(script)
.arg("GATEWAY_INTERFACE=\"CGI/1.1\"")
.arg("SERVER_SOFTWARE=\"Herb/0.3.1\"")
.arg("REQUEST_METHOD=\"GET\"")
.arg(format!("QUERY_STRING=\"{}\"", query))
.arg(format!("SCRIPT_NAME=\"{}\"", script))
let output = Command::new(format!("./{}", script))
.env("GATEWAY_INTERFACE", "CGI/1.1")
.env("SERVER_SOFTWARE", "Herb/0.4.0")
.env("REQUEST_METHOD", "GET")
.env("QUERY_STRING", query)
.env("SCRIPT_NAME", script)
.output()
.expect("failed to execute process");
let outputd = String::from_utf8_lossy(&output.stdout).to_string();
@ -115,7 +116,7 @@ fn generate_index(directory: String) -> String {
index = format!("{}<br/><a href={}>{:#?}</a>", index, format!("\"./{}\"", file.as_ref().unwrap().path().display().to_string()), file.unwrap().file_name());
}
return format!("{}<hr/>Generated by herb 0.3.1", index).to_string();
return format!("{}<hr/>Generated by herb 0.4.0", index).to_string();
}
@ -255,7 +256,7 @@ fn serve(mut stream: TcpStream) {
let contents = get_page(resource);
let header = "HTTP/1.1 200 OK\r\n";
let content_type = format!("Content-Type: {}\r\n", mime);
let server = "Server: Herb/0.3.1\r\n";
let server = "Server: Herb/0.4.0\r\n";
let extra_fields;
if cfg!(unix) {