diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e1edd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +latest.log +Cargo.lock \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index bbb1252..966c667 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "flowgate" -version = "0.1.0" +version = "0.1.1" edition = "2021" [dependencies] openssl = { version = "0.10.66", optional = true } rustls = { version = "0.23.13", optional = true } -rustls-pemfile = { version = "2.1.3", optional = true } +rustls-pemfile = { version = "2.2.0", optional = true } serde_yml = "0.0.12" log = "0.4.22" colog = "1.3.0" @@ -14,6 +14,5 @@ threadpool = "1.8.1" [features] default = ["use-openssl"] -# default = ["use-rustls"] use-openssl = ["dep:openssl"] use-rustls = ["dep:rustls", "dep:rustls-pemfile"] \ No newline at end of file diff --git a/conf.yml b/conf.yml index 0de786a..90621c8 100644 --- a/conf.yml +++ b/conf.yml @@ -1,12 +1,13 @@ http_host: localhost:80 # Http server host https_host: localhost:443 # Https server host -threadpool_size: 10 # Threadpool size (count of threads that accept requests) -connection_timeout: 10 # Read and write timeout of connections in seconds +threadpool_size: 10 # Threadpool size (count of threads that accept requests) (optional, default - 10) +connection_timeout: 10 # Read and write timeout of connections in seconds (optional, default - 10) sites: - domain: localhost # Site domain host: localhost:8080 # Http server host - support_keep_alive: false # Does server supports keep-alive connections + enable_keep_alive: true # Enable keep-alive connections (optional, default - true) + support_keep_alive: true # Does server supports keep-alive connections (optional, default - true) # ssl_cert: "/path/to/public/certificate.txt" # Ssl public certificate file (optional) # ssl_key: "/path/to/private/key.txt" # Ssl private key file (optional) diff --git a/src/flowgate/config.rs b/src/flowgate/config.rs index 5594aa8..c9cf7b0 100644 --- a/src/flowgate/config.rs +++ b/src/flowgate/config.rs @@ -1,6 +1,6 @@ use std::{fs, net::TcpStream, sync::Arc, time::Duration}; -use serde_yml::Value; +use serde_yml::{Number, Value}; use super::SslCert; @@ -9,6 +9,7 @@ pub struct SiteConfig { pub domain: String, pub host: String, pub ssl: Option, + pub enable_keep_alive: bool, pub support_keep_alive: bool } @@ -35,8 +36,10 @@ impl Config { let http_host = doc["http_host"].as_str()?.to_string(); let https_host = doc["https_host"].as_str()?.to_string(); - let threadpool_size = doc["threadpool_size"].as_u64()? as usize; - let connection_timeout = Duration::from_secs(doc["connection_timeout"].as_u64()?); + let threadpool_size = doc.get("threadpool_size") + .unwrap_or(&Value::Number(Number::from(10))).as_u64()? as usize; + let connection_timeout = Duration::from_secs(doc.get("connection_timeout") + .unwrap_or(&Value::Number(Number::from(10))).as_u64()?); let mut sites: Vec = Vec::new(); @@ -59,7 +62,12 @@ impl Config { domain: s.get("domain")?.as_str()?.to_string(), host: s.get("host")?.as_str()?.to_string(), ssl: cert, - support_keep_alive: s.get("support_keep_alive").map(|o| o.as_bool().unwrap()).unwrap_or(false) + enable_keep_alive: s.get("enable_keep_alive") + .map(|o| o.as_bool().unwrap()) + .unwrap_or(true), + support_keep_alive: s.get("support_keep_alive") + .map(|o| o.as_bool().unwrap()) + .unwrap_or(true) }; sites.push(site); diff --git a/src/flowgate/server.rs b/src/flowgate/server.rs index 4b1fa92..bbcf160 100644 --- a/src/flowgate/server.rs +++ b/src/flowgate/server.rs @@ -251,9 +251,9 @@ impl FlowgateServer { info!("{} > {} http://{}{}", addr.to_string(), method, host, page); } - if keep_alive { + if keep_alive && site.enable_keep_alive { loop { - if !site.clone().support_keep_alive { + if !site.support_keep_alive { site_stream.shutdown(Shutdown::Both).ok()?; } @@ -282,7 +282,7 @@ impl FlowgateServer { } } - if !site.clone().support_keep_alive { + if !site.support_keep_alive { site_stream = site.clone().connect()? }