From 94516c95bb6cd28ebb757823d2b8092608511112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Sat, 12 Mar 2022 00:35:54 +0300 Subject: [PATCH] feat(config): support setting the timeout for HTTP requests --- config.toml | 1 + src/config.rs | 3 +++ src/main.rs | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index 76be072..305b2b0 100644 --- a/config.toml +++ b/config.toml @@ -6,6 +6,7 @@ address="127.0.0.1:8000" #workers=4 max_content_length="10MB" upload_path="./upload" +timeout="30s" [paste] random_url = { enabled = true, type = "petname", words = 2, separator = "-" } diff --git a/src/config.rs b/src/config.rs index 30e7c75..7c02da2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,9 @@ pub struct ServerConfig { pub max_content_length: Byte, /// Storage path. pub upload_path: PathBuf, + /// Request timeout. + #[serde(default, with = "humantime_serde")] + pub timeout: Option, /// Authentication token. pub auth_token: Option, } diff --git a/src/main.rs b/src/main.rs index 8792c8c..0929bd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,11 @@ async fn main() -> IoResult<()> { // Create a HTTP server. let mut http_server = HttpServer::new(move || { let http_client = ClientBuilder::default() - .timeout(Duration::from_secs(30)) + .timeout( + server_config + .timeout + .unwrap_or_else(|| Duration::from_secs(30)), + ) .disable_redirects() .finish(); App::new()