mirror of
https://github.com/DefectingCat/candy
synced 2025-07-15 16:51:34 +00:00
feat(timeout): add connection timeout
remove keey_alive
This commit is contained in:
@ -5,7 +5,7 @@ wasm = "application/wasm"
|
||||
[[host]]
|
||||
ip = "0.0.0.0"
|
||||
port = 4000
|
||||
keep_alive = 15
|
||||
timeout = 15
|
||||
|
||||
[host.headers]
|
||||
X-Powered-By = "candy"
|
||||
|
@ -1,7 +1,5 @@
|
||||
use crate::{
|
||||
consts::{
|
||||
host_index, insert_default_mimes, keep_alive_timeout_default, mime_default, types_default,
|
||||
},
|
||||
consts::{host_index, insert_default_mimes, mime_default, timeout_default, types_default},
|
||||
error::Result,
|
||||
};
|
||||
use std::{borrow::Cow, collections::BTreeMap, fs};
|
||||
@ -39,8 +37,8 @@ pub struct SettingHost {
|
||||
#[serde(skip_deserializing, skip_serializing)]
|
||||
pub route_map: HostRouteMap,
|
||||
/// HTTP keep-alive timeout
|
||||
#[serde(default = "keep_alive_timeout_default")]
|
||||
pub keep_alive: u16,
|
||||
#[serde(default = "timeout_default")]
|
||||
pub timeout: u16,
|
||||
pub headers: Option<BTreeMap<String, String>>,
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@ pub fn host_index() -> Vec<String> {
|
||||
HOST_INDEX.map(|h| h.to_string()).to_vec()
|
||||
}
|
||||
|
||||
// default http keep alive timeout
|
||||
pub const KEEP_ALIVE_TIMEOUTD_EFAULT: u16 = 75;
|
||||
pub fn keep_alive_timeout_default() -> u16 {
|
||||
KEEP_ALIVE_TIMEOUTD_EFAULT
|
||||
// default http connection timeout
|
||||
pub const TIMEOUT_EFAULT: u16 = 75;
|
||||
pub fn timeout_default() -> u16 {
|
||||
TIMEOUT_EFAULT
|
||||
}
|
||||
|
||||
// default mime type for unknow file
|
||||
|
@ -62,7 +62,7 @@ impl SettingHost {
|
||||
_ = graceful.shutdown() => {
|
||||
info!("Gracefully shutdown!");
|
||||
},
|
||||
_ = tokio::time::sleep(Duration::from_secs(self.keep_alive.into())) => {
|
||||
_ = tokio::time::sleep(Duration::from_secs(self.timeout.into())) => {
|
||||
error!("Waited 10 seconds for graceful shutdown, aborting...");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user