0.4.2: If there is no query string for CGI then the QUERY_STRING env var isn't set.

This commit is contained in:
abbie 2022-09-17 09:37:42 +01:00
parent 66dfbd2291
commit ba06ad686a
No known key found for this signature in database
GPG key ID: A575D2415E5E5B6D
3 changed files with 23 additions and 13 deletions

2
Cargo.lock generated
View file

@ -4,4 +4,4 @@ version = 3
[[package]] [[package]]
name = "herb" name = "herb"
version = "0.4.1" version = "0.4.2"

View file

@ -1,6 +1,6 @@
[package] [package]
name = "herb" name = "herb"
version = "0.4.1" version = "0.4.2"
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

View file

@ -23,15 +23,25 @@ fn process_cgi(filename: String) -> String {
} }
println!("{}", script); println!("{}", script);
let output;
let output = Command::new(format!("./{}", script)) if query != "" {
.env("GATEWAY_INTERFACE", "CGI/1.1") output = Command::new(format!("./{}", script))
.env("SERVER_SOFTWARE", "Herb/0.4.1") .env("GATEWAY_INTERFACE", "CGI/1.1")
.env("REQUEST_METHOD", "GET") .env("SERVER_SOFTWARE", "Herb/0.4.2")
.env("QUERY_STRING", query) .env("REQUEST_METHOD", "GET")
.env("SCRIPT_NAME", script) .env("QUERY_STRING", query)
.output() .env("SCRIPT_NAME", script)
.expect("failed to execute process"); .output()
.expect("failed to execute process");
} else {
output = Command::new(format!("./{}", script))
.env("GATEWAY_INTERFACE", "CGI/1.1")
.env("SERVER_SOFTWARE", "Herb/0.4.2")
.env("REQUEST_METHOD", "GET")
.env("SCRIPT_NAME", script)
.output()
.expect("failed to execute process");
}
let outputd = String::from_utf8_lossy(&output.stdout).to_string(); let outputd = String::from_utf8_lossy(&output.stdout).to_string();
return outputd; return outputd;
} }
@ -116,7 +126,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()); 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.4.1", index).to_string(); return format!("{}<hr/>Generated by herb 0.4.2", index).to_string();
} }
@ -256,7 +266,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.4.1\r\n"; let server = "Server: Herb/0.4.2\r\n";
let extra_fields; let extra_fields;
if cfg!(unix) { if cfg!(unix) {