0.8.1: add logging config param.
This commit is contained in:
parent
2bb5ac2b24
commit
5c9d92523c
4 changed files with 28 additions and 14 deletions
|
@ -1 +1 @@
|
||||||
11
|
12
|
||||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -10,7 +10,7 @@ checksum = "17cbf58e19f2bda088d8c4c95a46b41895375e15a2d63dd686a4273f8c43d46b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.8.0-binugs"
|
version = "0.8.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"frostwalker",
|
"frostwalker",
|
||||||
"packeteer",
|
"packeteer",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "herb"
|
name = "herb"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -29,16 +29,17 @@ struct Settings {
|
||||||
cgi: bool,
|
cgi: bool,
|
||||||
index_generation: bool,
|
index_generation: bool,
|
||||||
address: String,
|
address: String,
|
||||||
|
logging: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
fn new() -> Settings {
|
fn new() -> Settings {
|
||||||
return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string()};
|
return Settings { cgi: true, index_generation: true, address: "0.0.0.0:8080".to_string(), logging: false};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_cgi(filename: String) -> Option<Vec<u8>> {
|
fn process_cgi(filename: String) -> Option<Vec<u8>> {
|
||||||
// This is gonna be the boggiest implementation of CGI that anyone
|
// This is gonna be the bodgiest implementation of CGI that anyone
|
||||||
// has ever seen in the history of the fucking world
|
// has ever seen in the history of the fucking world
|
||||||
|
|
||||||
let query;
|
let query;
|
||||||
|
@ -102,7 +103,6 @@ fn process_cgi_with_path(filename: String, segments: Vec<String>, location: i32)
|
||||||
}
|
}
|
||||||
|
|
||||||
path = format!("{}/", path);
|
path = format!("{}/", path);
|
||||||
println!("{}", path);
|
|
||||||
let output;
|
let output;
|
||||||
if query != "".to_string() {
|
if query != "".to_string() {
|
||||||
output = Command::new(format!("./{}", script))
|
output = Command::new(format!("./{}", script))
|
||||||
|
@ -218,7 +218,9 @@ fn get_page(filename: String, settings: Settings) -> GetPageResult {
|
||||||
|
|
||||||
let mut resultstruct = GetPageResult { is500: false, is502: false, is403: false, contents: vec![], iscgi: false };
|
let mut resultstruct = GetPageResult { is500: false, is502: false, is403: false, contents: vec![], iscgi: false };
|
||||||
|
|
||||||
|
if settings.logging {
|
||||||
println!("{} {} {}", path, checks, index);
|
println!("{} {} {}", path, checks, index);
|
||||||
|
}
|
||||||
|
|
||||||
if checks == true && index == false {
|
if checks == true && index == false {
|
||||||
if path.contains(".") != true && path.contains(".cgi?") != true {
|
if path.contains(".") != true && path.contains(".cgi?") != true {
|
||||||
|
@ -329,8 +331,9 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
||||||
let output;
|
let output;
|
||||||
|
|
||||||
if &request.method == "GET" {
|
if &request.method == "GET" {
|
||||||
|
if settings.logging {
|
||||||
println!("Stream sent GET request.");
|
println!("Stream sent GET request.");
|
||||||
|
}
|
||||||
if request.location.segments.len() != 0 {
|
if request.location.segments.len() != 0 {
|
||||||
let segclone = request.location.segments.clone();
|
let segclone = request.location.segments.clone();
|
||||||
path = unwrap_url_into_segments(request.location);
|
path = unwrap_url_into_segments(request.location);
|
||||||
|
@ -393,7 +396,9 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let resource = Resource { contents: "<!DOCTYPE HTML><html><body><h1>501 Not Implemented</h1><p>The request sent by your web browser cannot be handled by this server software.</p></body></html>".to_string().into_bytes(), status_code: 501, mime: "text/html".to_string(), iscgi: false };
|
let resource = Resource { contents: "<!DOCTYPE HTML><html><body><h1>501 Not Implemented</h1><p>The request sent by your web browser cannot be handled by this server software.</p></body></html>".to_string().into_bytes(), status_code: 501, mime: "text/html".to_string(), iscgi: false };
|
||||||
|
if settings.logging {
|
||||||
println!("Stream sent unhandlable request.");
|
println!("Stream sent unhandlable request.");
|
||||||
|
}
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,7 +430,10 @@ fn process_request(request: Vec<u8>, settings: Settings) -> Resource {
|
||||||
|
|
||||||
fn serve(mut stream: TcpStream, settings: Settings) {
|
fn serve(mut stream: TcpStream, settings: Settings) {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
if settings.logging {
|
||||||
println!("Stream thread created.");
|
println!("Stream thread created.");
|
||||||
|
}
|
||||||
|
|
||||||
let mut request = Vec::new();
|
let mut request = Vec::new();
|
||||||
let mut reader = BufReader::new(&mut stream);
|
let mut reader = BufReader::new(&mut stream);
|
||||||
reader
|
reader
|
||||||
|
@ -477,10 +485,14 @@ fn process_settings() -> Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
if hashmap.get("index_generation").is_some() {
|
if hashmap.get("index_generation").is_some() {
|
||||||
println!("a");
|
|
||||||
if hashmap.get("index_generation").unwrap_or(&"".to_string()).parse::<bool>().is_ok() {
|
if hashmap.get("index_generation").unwrap_or(&"".to_string()).parse::<bool>().is_ok() {
|
||||||
settings.index_generation = hashmap.get("index_generation").unwrap_or(&"true".to_string()).parse::<bool>().unwrap_or(true);
|
settings.index_generation = hashmap.get("index_generation").unwrap_or(&"true".to_string()).parse::<bool>().unwrap_or(true);
|
||||||
println!("{}", settings.index_generation);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if hashmap.get("logging").is_some() {
|
||||||
|
if hashmap.get("logging").unwrap_or(&"".to_string()).parse::<bool>().is_ok() {
|
||||||
|
settings.logging = hashmap.get("logging").unwrap_or(&"false".to_string()).parse::<bool>().unwrap_or(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,7 +508,9 @@ fn main() -> std::io::Result<()> {
|
||||||
let listen = TcpListener::bind(settings.address.clone())?;
|
let listen = TcpListener::bind(settings.address.clone())?;
|
||||||
|
|
||||||
for stream in listen.incoming() {
|
for stream in listen.incoming() {
|
||||||
|
if settings.logging {
|
||||||
println!("Serving incoming stream.");
|
println!("Serving incoming stream.");
|
||||||
|
}
|
||||||
serve(stream?, settings.clone());
|
serve(stream?, settings.clone());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue