configi shamanstvo

This commit is contained in:
MeexReay 2024-10-04 00:46:10 +03:00
parent b06518846f
commit 352eb6c05a
5 changed files with 24 additions and 13 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
latest.log
Cargo.lock

View File

@ -1,12 +1,12 @@
[package] [package]
name = "flowgate" name = "flowgate"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
openssl = { version = "0.10.66", optional = true } openssl = { version = "0.10.66", optional = true }
rustls = { version = "0.23.13", 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" serde_yml = "0.0.12"
log = "0.4.22" log = "0.4.22"
colog = "1.3.0" colog = "1.3.0"
@ -14,6 +14,5 @@ threadpool = "1.8.1"
[features] [features]
default = ["use-openssl"] default = ["use-openssl"]
# default = ["use-rustls"]
use-openssl = ["dep:openssl"] use-openssl = ["dep:openssl"]
use-rustls = ["dep:rustls", "dep:rustls-pemfile"] use-rustls = ["dep:rustls", "dep:rustls-pemfile"]

View File

@ -1,12 +1,13 @@
http_host: localhost:80 # Http server host http_host: localhost:80 # Http server host
https_host: localhost:443 # Https server host https_host: localhost:443 # Https server host
threadpool_size: 10 # Threadpool size (count of threads that accept requests) 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 connection_timeout: 10 # Read and write timeout of connections in seconds (optional, default - 10)
sites: sites:
- domain: localhost # Site domain - domain: localhost # Site domain
host: localhost:8080 # Http server host 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_cert: "/path/to/public/certificate.txt" # Ssl public certificate file (optional)
# ssl_key: "/path/to/private/key.txt" # Ssl private key file (optional) # ssl_key: "/path/to/private/key.txt" # Ssl private key file (optional)

View File

@ -1,6 +1,6 @@
use std::{fs, net::TcpStream, sync::Arc, time::Duration}; use std::{fs, net::TcpStream, sync::Arc, time::Duration};
use serde_yml::Value; use serde_yml::{Number, Value};
use super::SslCert; use super::SslCert;
@ -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 enable_keep_alive: bool,
pub support_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 http_host = doc["http_host"].as_str()?.to_string();
let https_host = doc["https_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 threadpool_size = doc.get("threadpool_size")
let connection_timeout = Duration::from_secs(doc["connection_timeout"].as_u64()?); .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<SiteConfig> = Vec::new(); let mut sites: Vec<SiteConfig> = Vec::new();
@ -59,7 +62,12 @@ 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) 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); sites.push(site);

View File

@ -251,9 +251,9 @@ impl FlowgateServer {
info!("{} > {} http://{}{}", addr.to_string(), method, host, page); info!("{} > {} http://{}{}", addr.to_string(), method, host, page);
} }
if keep_alive { if keep_alive && site.enable_keep_alive {
loop { loop {
if !site.clone().support_keep_alive { if !site.support_keep_alive {
site_stream.shutdown(Shutdown::Both).ok()?; 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()? site_stream = site.clone().connect()?
} }