add keep-alive default timeout

This commit is contained in:
xfy
2024-04-26 11:45:07 +08:00
parent cc0ba87bcf
commit bd9df5235c
4 changed files with 16 additions and 1 deletions

View File

@ -6,3 +6,4 @@ A tiny web server built with Rust.
- [ ] HTTP Etag: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag#etag_value
- [x] Graceful shutdown
- [ ] `keep-alive` timeout setting

View File

@ -3,6 +3,8 @@ ip = "0.0.0.0"
port = 4000
# index file name and format
index = ["index.html"]
# http keep alive timeout
keep-alive-time = 75
[[host.route]]
# route path: GET /
location = "/"

View File

@ -1,4 +1,7 @@
use crate::error::Result;
use crate::{
consts::{keep_alive_timeoutd_efault, KEEP_ALIVE_TIMEOUTD_EFAULT},
error::Result,
};
use std::{collections::BTreeMap, fs};
use serde::Deserialize;
@ -22,6 +25,9 @@ pub struct SettingHost {
pub route_map: BTreeMap<String, SettingRoute>,
/// Index files format
pub index: Vec<String>,
/// HTTP keep-alive timeout
#[serde(default = "keep_alive_timeoutd_efault")]
pub keep_alive: u16,
}
#[derive(Deserialize, Clone, Debug)]

View File

@ -4,3 +4,9 @@ pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const OS: &str = env::consts::OS;
pub const ARCH: &str = env::consts::ARCH;
// config defaults
pub const KEEP_ALIVE_TIMEOUTD_EFAULT: u16 = 75;
pub fn keep_alive_timeoutd_efault() -> u16 {
KEEP_ALIVE_TIMEOUTD_EFAULT
}