From 72d4a043db48bb8196fbf60b99f9d59ef827bf8b Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 22 Mar 2025 14:20:07 +0800 Subject: Configurable timeout --- config.go | 3 +++ forge.scfg | 4 ++++ main.go | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 5382bbe..3721fd6 100644 --- a/config.go +++ b/config.go @@ -21,6 +21,9 @@ var config struct { Addr string `scfg:"addr"` CookieExpiry int `scfg:"cookie_expiry"` Root string `scfg:"root"` + ReadTimeout uint `scfg:"read_timeout"` + WriteTimeout uint `scfg:"write_timeout"` + IdleTimeout uint `scfg:"idle_timeout"` } `scfg:"http"` Hooks struct { Socket string `scfg:"socket"` diff --git a/forge.scfg b/forge.scfg index 42a4b57..e2b703e 100644 --- a/forge.scfg +++ b/forge.scfg @@ -13,6 +13,10 @@ http { # What is the canonical URL of the web root? root https://forge.example.org + + read_timeout 120 + write_timeout 120 + idle_timeout 120 } irc { diff --git a/main.go b/main.go index 1530d90..444e5b0 100644 --- a/main.go +++ b/main.go @@ -89,9 +89,9 @@ func main() { } server := http.Server{ Handler: &forgeHTTPRouter{}, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, - IdleTimeout: 60 * time.Second, + ReadTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, + WriteTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, + IdleTimeout: time.Duration(config.HTTP.ReadTimeout) * time.Second, } //exhaustruct:ignore clog.Info("Listening HTTP on " + config.HTTP.Net + " " + config.HTTP.Addr) go func() { -- cgit v1.2.3