From 4d2a160ccb0cbcc1d89f48a966b54bf0576fee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Thu, 24 Jun 2021 21:56:47 +0200 Subject: [PATCH] chore: configurable request timeout --- README.md | 1 + config.default.yml | 1 + config/config.go | 1 + main.go | 12 ++++++------ version.txt | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c48d8bc..65448ee 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,7 @@ You can specify configuration options either via a config file (default: `config | `server.listen_ipv4` | `WAKAPI_LISTEN_IPV4` | `127.0.0.1` | IPv4 network address to listen on (leave blank to disable IPv4) | | `server.listen_ipv6` | `WAKAPI_LISTEN_IPV6` | `::1` | IPv6 network address to listen on (leave blank to disable IPv6) | | `server.listen_socket` | `WAKAPI_LISTEN_SOCKET` | - | UNIX socket to listen on (leave blank to disable UNIX socket) | +| `server.timeout_sec` | `WAKAPI_TIMEOUT_SEC` | `30` | Request timeout in seconds | | `server.tls_cert_path` | `WAKAPI_TLS_CERT_PATH` | - | Path of SSL server certificate (leave blank to not use HTTPS) | | `server.tls_key_path` | `WAKAPI_TLS_KEY_PATH` | - | Path of SSL server private key (leave blank to not use HTTPS) | | `server.base_path` | `WAKAPI_BASE_PATH` | `/` | Web base path (change when running behind a proxy under a sub-path) | diff --git a/config.default.yml b/config.default.yml index 09b8f22..f3913f3 100644 --- a/config.default.yml +++ b/config.default.yml @@ -4,6 +4,7 @@ server: listen_ipv4: 127.0.0.1 # leave blank to disable ipv4 listen_ipv6: ::1 # leave blank to disable ipv6 listen_socket: # leave blank to disable unix sockets + timeout_sec: 30 # request timeout tls_cert_path: # leave blank to not use https tls_key_path: # leave blank to not use https port: 3000 diff --git a/config/config.go b/config/config.go index 4872b1a..233bfd9 100644 --- a/config/config.go +++ b/config/config.go @@ -99,6 +99,7 @@ type serverConfig struct { ListenIpV4 string `yaml:"listen_ipv4" default:"127.0.0.1" env:"WAKAPI_LISTEN_IPV4"` ListenIpV6 string `yaml:"listen_ipv6" default:"::1" env:"WAKAPI_LISTEN_IPV6"` ListenSocket string `yaml:"listen_socket" default:"" env:"WAKAPI_LISTEN_SOCKET"` + TimeoutSec int `yaml:"timeout_sec" default:"30" env:"WAKAPI_TIMEOUT_SEC"` BasePath string `yaml:"base_path" default:"/" env:"WAKAPI_BASE_PATH"` PublicUrl string `yaml:"public_url" default:"http://localhost:3000" env:"WAKAPI_PUBLIC_URL"` TlsCertPath string `yaml:"tls_cert_path" default:"" env:"WAKAPI_TLS_CERT_PATH"` diff --git a/main.go b/main.go index f1a64cf..0287f09 100644 --- a/main.go +++ b/main.go @@ -250,8 +250,8 @@ func listen(handler http.Handler) { s4 = &http.Server{ Handler: handler, Addr: bindString4, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, + ReadTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, + WriteTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, } } @@ -261,8 +261,8 @@ func listen(handler http.Handler) { s6 = &http.Server{ Handler: handler, Addr: bindString6, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, + ReadTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, + WriteTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, } } @@ -270,8 +270,8 @@ func listen(handler http.Handler) { if config.Server.ListenSocket != "" { sSocket = &http.Server{ Handler: handler, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, + ReadTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, + WriteTimeout: time.Duration(config.Server.TimeoutSec) * time.Second, } } diff --git a/version.txt b/version.txt index 5e57fb8..83cf0d9 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.29.0 +1.29.1