keep alive config settings

This commit is contained in:
MeexReay 2024-09-14 01:08:28 +03:00
parent b15a198d2b
commit cbd0067cb0
3 changed files with 14 additions and 1 deletions

View File

@ -6,9 +6,12 @@ sites:
# host: localhost:8080 # host: localhost:8080
# ssl_cert: "/path/to/public/certificate.txt" # ssl_cert: "/path/to/public/certificate.txt"
# ssl_key: "/path/to/private/key.txt" # ssl_key: "/path/to/private/key.txt"
# support_keep_alive: true
# - domain: sub.example.com # Domain with no SSL # - domain: sub.example.com # Domain with no SSL
# host: localhost:8081 # host: localhost:8081
# support_keep_alive: true
- domain: localhost - domain: localhost
host: localhost:8080 host: localhost:8080
support_keep_alive: false

View File

@ -9,6 +9,7 @@ pub struct SiteConfig {
pub domain: String, pub domain: String,
pub host: String, pub host: String,
pub ssl: Option<SslCert>, pub ssl: Option<SslCert>,
pub support_keep_alive: bool
} }
impl SiteConfig { impl SiteConfig {
@ -53,6 +54,7 @@ impl Config {
domain: s.get("domain")?.as_str()?.to_string(), domain: s.get("domain")?.as_str()?.to_string(),
host: s.get("host")?.as_str()?.to_string(), host: s.get("host")?.as_str()?.to_string(),
ssl: cert, ssl: cert,
support_keep_alive: s.get("support_keep_alive").map(|o| o.as_bool().unwrap()).unwrap_or(false)
}; };
sites.push(site); sites.push(site);

View File

@ -165,7 +165,7 @@ impl FlowgateServer {
} }
let site = site?.clone(); let site = site?.clone();
let mut site_stream = site.connect()?; let mut site_stream = site.clone().connect()?;
site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?; site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?;
@ -195,6 +195,10 @@ impl FlowgateServer {
if keep_alive { if keep_alive {
loop { loop {
if !site.clone().support_keep_alive {
site_stream.shutdown(Shutdown::Both).ok()?;
}
let mut reqst_data: Vec<u8> = vec![0; 4096]; let mut reqst_data: Vec<u8> = vec![0; 4096];
stream.read(&mut reqst_data).ok()?; stream.read(&mut reqst_data).ok()?;
@ -220,6 +224,10 @@ impl FlowgateServer {
} }
} }
if !site.clone().support_keep_alive {
site_stream = site.clone().connect()?
}
site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?; site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?;
if content_length != 0 && content_length > body.len() { if content_length != 0 && content_length > body.len() {