feat(timeout): add connection timeout

remove keey_alive
This commit is contained in:
xfy
2024-06-27 15:31:59 +08:00
parent c4c598bb82
commit 80c18df856
4 changed files with 9 additions and 11 deletions

View File

@ -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"

View File

@ -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>>,
}

View File

@ -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

View 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...");
}
}