diff --git a/internal/config/config_test.go b/internal/config/config_test.go index cc4a24a4..2ddac960 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1776,12 +1776,22 @@ func TestHTTPServerTimeout(t *testing.T) { t.Fatalf(`Parsing failure: %v`, err) } - expected := 342 + expected := 342 * time.Second result := opts.HTTPServerTimeout() if result != expected { t.Fatalf(`Unexpected HTTP_SERVER_TIMEOUT value, got %d instead of %d`, result, expected) } + + sorted := opts.SortedOptions(false) + i := slices.IndexFunc(sorted, func(opt *option) bool { + return opt.Key == "HTTP_SERVER_TIMEOUT" + }) + + expectedSerialized := 342 + if got := sorted[i].Value; got != expectedSerialized { + t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized) + } } func TestDefaultHTTPServerTimeoutValue(t *testing.T) { diff --git a/internal/config/options.go b/internal/config/options.go index 10b6cfe5..594f5286 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -77,7 +77,7 @@ const ( defaultHTTPClientTimeout = 20 defaultHTTPClientMaxBodySize = 15 defaultHTTPClientProxy = "" - defaultHTTPServerTimeout = 300 + defaultHTTPServerTimeout = 300 * time.Second defaultAuthProxyHeader = "" defaultAuthProxyUserCreation = false defaultMaintenanceMode = false @@ -170,7 +170,7 @@ type options struct { httpClientProxyURL *url.URL httpClientProxies []string httpClientUserAgent string - httpServerTimeout int + httpServerTimeout time.Duration authProxyHeader string authProxyUserCreation bool maintenanceMode bool @@ -617,8 +617,8 @@ func (o *options) HasHTTPClientProxiesConfigured() bool { return len(o.httpClientProxies) > 0 } -// HTTPServerTimeout returns the time limit in seconds before the HTTP server cancel the request. -func (o *options) HTTPServerTimeout() int { +// HTTPServerTimeout returns the time limit before the HTTP server cancel the request. +func (o *options) HTTPServerTimeout() time.Duration { return o.httpServerTimeout } @@ -745,7 +745,7 @@ func (o *options) SortedOptions(redactSecret bool) []*option { "HTTP_CLIENT_PROXY": clientProxyURLRedacted, "HTTP_CLIENT_TIMEOUT": o.httpClientTimeout, "HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent, - "HTTP_SERVER_TIMEOUT": o.httpServerTimeout, + "HTTP_SERVER_TIMEOUT": int(o.httpServerTimeout.Seconds()), "HTTP_SERVICE": o.httpService, "INVIDIOUS_INSTANCE": o.invidiousInstance, "KEY_FILE": o.certKeyFile, diff --git a/internal/config/parser.go b/internal/config/parser.go index 50b506d4..71a207c2 100644 --- a/internal/config/parser.go +++ b/internal/config/parser.go @@ -219,7 +219,7 @@ func (p *parser) parseLines(lines []string) (err error) { case "HTTP_CLIENT_USER_AGENT": p.opts.httpClientUserAgent = parseString(value, defaultHTTPClientUserAgent) case "HTTP_SERVER_TIMEOUT": - p.opts.httpServerTimeout = parseInt(value, defaultHTTPServerTimeout) + p.opts.httpServerTimeout = parseInterval(value, time.Second, defaultHTTPServerTimeout) case "AUTH_PROXY_HEADER": p.opts.authProxyHeader = parseString(value, defaultAuthProxyHeader) case "AUTH_PROXY_USER_CREATION": diff --git a/internal/http/server/httpd.go b/internal/http/server/httpd.go index 8a649fc3..32bf2275 100644 --- a/internal/http/server/httpd.go +++ b/internal/http/server/httpd.go @@ -12,7 +12,6 @@ import ( "os" "strconv" "strings" - "time" "miniflux.app/v2/internal/api" "miniflux.app/v2/internal/config" @@ -67,9 +66,9 @@ func StartWebServer(store *storage.Storage, pool *worker.Pool) []*http.Server { for i, listenAddr := range listenAddresses { server := &http.Server{ - ReadTimeout: time.Duration(config.Opts.HTTPServerTimeout()) * time.Second, - WriteTimeout: time.Duration(config.Opts.HTTPServerTimeout()) * time.Second, - IdleTimeout: time.Duration(config.Opts.HTTPServerTimeout()) * time.Second, + ReadTimeout: config.Opts.HTTPServerTimeout(), + WriteTimeout: config.Opts.HTTPServerTimeout(), + IdleTimeout: config.Opts.HTTPServerTimeout(), Handler: setupHandler(store, pool), }