mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
refactor(fetcher): use time.Duration for client timeout values
All functions use time.Duration, so instead of converting everywhere, do it once.
This commit is contained in:
parent
71af68becd
commit
30453ad7ec
5 changed files with 51 additions and 22 deletions
|
@ -1607,12 +1607,22 @@ func TestMediaProxyHTTPClientTimeout(t *testing.T) {
|
|||
t.Fatalf(`Parsing failure: %v`, err)
|
||||
}
|
||||
|
||||
expected := 24
|
||||
expected := 24 * time.Second
|
||||
result := opts.MediaProxyHTTPClientTimeout()
|
||||
|
||||
if result != expected {
|
||||
t.Fatalf(`Unexpected MEDIA_PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
||||
}
|
||||
|
||||
sorted := opts.SortedOptions(false)
|
||||
i := slices.IndexFunc(sorted, func(opt *option) bool {
|
||||
return opt.Key == "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT"
|
||||
})
|
||||
|
||||
expectedSerialized := 24
|
||||
if got := sorted[i].Value; got != expectedSerialized {
|
||||
t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultMediaProxyHTTPClientTimeoutValue(t *testing.T) {
|
||||
|
@ -1630,6 +1640,16 @@ func TestDefaultMediaProxyHTTPClientTimeoutValue(t *testing.T) {
|
|||
if result != expected {
|
||||
t.Fatalf(`Unexpected MEDIA_PROXY_HTTP_CLIENT_TIMEOUT value, got %d instead of %d`, result, expected)
|
||||
}
|
||||
|
||||
sorted := opts.SortedOptions(false)
|
||||
i := slices.IndexFunc(sorted, func(opt *option) bool {
|
||||
return opt.Key == "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT"
|
||||
})
|
||||
|
||||
expectedSerialized := int(defaultMediaProxyHTTPClientTimeout / time.Second)
|
||||
if got := sorted[i].Value; got != expectedSerialized {
|
||||
t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMediaProxyCustomURL(t *testing.T) {
|
||||
|
@ -1706,12 +1726,22 @@ func TestHTTPClientTimeout(t *testing.T) {
|
|||
t.Fatalf(`Parsing failure: %v`, err)
|
||||
}
|
||||
|
||||
expected := 42
|
||||
expected := 42 * time.Second
|
||||
result := opts.HTTPClientTimeout()
|
||||
|
||||
if result != expected {
|
||||
t.Fatalf(`Unexpected HTTP_CLIENT_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_CLIENT_TIMEOUT"
|
||||
})
|
||||
|
||||
expectedSerialized := 42
|
||||
if got := sorted[i].Value; got != expectedSerialized {
|
||||
t.Fatalf(`Unexpected value in option output, got %q instead of %q`, got, expectedSerialized)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultHTTPClientTimeoutValue(t *testing.T) {
|
||||
|
|
|
@ -52,7 +52,7 @@ const (
|
|||
defaultCleanupArchiveUnreadDays = 180
|
||||
defaultCleanupArchiveBatchSize = 10000
|
||||
defaultCleanupRemoveSessionsDays = 30
|
||||
defaultMediaProxyHTTPClientTimeout = 120
|
||||
defaultMediaProxyHTTPClientTimeout = 120 * time.Second
|
||||
defaultMediaProxyMode = "http-only"
|
||||
defaultMediaResourceTypes = "image"
|
||||
defaultMediaProxyURL = ""
|
||||
|
@ -74,7 +74,7 @@ const (
|
|||
defaultOauth2OidcProviderName = "OpenID Connect"
|
||||
defaultOAuth2Provider = ""
|
||||
defaultDisableLocalAuth = false
|
||||
defaultHTTPClientTimeout = 20
|
||||
defaultHTTPClientTimeout = 20 * time.Second
|
||||
defaultHTTPClientMaxBodySize = 15
|
||||
defaultHTTPClientProxy = ""
|
||||
defaultHTTPServerTimeout = 300 * time.Second
|
||||
|
@ -145,7 +145,7 @@ type options struct {
|
|||
createAdmin bool
|
||||
adminUsername string
|
||||
adminPassword string
|
||||
mediaProxyHTTPClientTimeout int
|
||||
mediaProxyHTTPClientTimeout time.Duration
|
||||
mediaProxyMode string
|
||||
mediaProxyResourceTypes []string
|
||||
mediaProxyCustomURL *url.URL
|
||||
|
@ -165,7 +165,7 @@ type options struct {
|
|||
oidcProviderName string
|
||||
oauth2Provider string
|
||||
disableLocalAuth bool
|
||||
httpClientTimeout int
|
||||
httpClientTimeout time.Duration
|
||||
httpClientMaxBodySize int64
|
||||
httpClientProxyURL *url.URL
|
||||
httpClientProxies []string
|
||||
|
@ -567,8 +567,8 @@ func (o *options) MediaCustomProxyURL() *url.URL {
|
|||
return o.mediaProxyCustomURL
|
||||
}
|
||||
|
||||
// MediaProxyHTTPClientTimeout returns the time limit in seconds before the proxy HTTP client cancel the request.
|
||||
func (o *options) MediaProxyHTTPClientTimeout() int {
|
||||
// MediaProxyHTTPClientTimeout returns the time limit before the proxy HTTP client cancel the request.
|
||||
func (o *options) MediaProxyHTTPClientTimeout() time.Duration {
|
||||
return o.mediaProxyHTTPClientTimeout
|
||||
}
|
||||
|
||||
|
@ -588,7 +588,7 @@ func (o *options) HasSchedulerService() bool {
|
|||
}
|
||||
|
||||
// HTTPClientTimeout returns the time limit in seconds before the HTTP client cancel the request.
|
||||
func (o *options) HTTPClientTimeout() int {
|
||||
func (o *options) HTTPClientTimeout() time.Duration {
|
||||
return o.httpClientTimeout
|
||||
}
|
||||
|
||||
|
@ -743,7 +743,7 @@ func (o *options) SortedOptions(redactSecret bool) []*option {
|
|||
"HTTP_CLIENT_MAX_BODY_SIZE": o.httpClientMaxBodySize,
|
||||
"HTTP_CLIENT_PROXIES": clientProxyURLsRedacted,
|
||||
"HTTP_CLIENT_PROXY": clientProxyURLRedacted,
|
||||
"HTTP_CLIENT_TIMEOUT": o.httpClientTimeout,
|
||||
"HTTP_CLIENT_TIMEOUT": int(o.httpClientTimeout.Seconds()),
|
||||
"HTTP_CLIENT_USER_AGENT": o.httpClientUserAgent,
|
||||
"HTTP_SERVER_TIMEOUT": int(o.httpServerTimeout.Seconds()),
|
||||
"HTTP_SERVICE": o.httpService,
|
||||
|
@ -774,7 +774,7 @@ func (o *options) SortedOptions(redactSecret bool) []*option {
|
|||
"POLLING_LIMIT_PER_HOST": o.pollingLimitPerHost,
|
||||
"POLLING_PARSING_ERROR_LIMIT": o.pollingParsingErrorLimit,
|
||||
"POLLING_SCHEDULER": o.pollingScheduler,
|
||||
"MEDIA_PROXY_HTTP_CLIENT_TIMEOUT": o.mediaProxyHTTPClientTimeout,
|
||||
"MEDIA_PROXY_HTTP_CLIENT_TIMEOUT": int(o.mediaProxyHTTPClientTimeout.Seconds()),
|
||||
"MEDIA_PROXY_RESOURCE_TYPES": o.mediaProxyResourceTypes,
|
||||
"MEDIA_PROXY_MODE": o.mediaProxyMode,
|
||||
"MEDIA_PROXY_PRIVATE_KEY": mediaProxyPrivateKeyValue,
|
||||
|
|
|
@ -161,7 +161,7 @@ func (p *parser) parseLines(lines []string) (err error) {
|
|||
case "SCHEDULER_ROUND_ROBIN_MAX_INTERVAL":
|
||||
p.opts.schedulerRoundRobinMaxInterval = parseInterval(value, time.Minute, defaultSchedulerRoundRobinMaxInterval)
|
||||
case "MEDIA_PROXY_HTTP_CLIENT_TIMEOUT":
|
||||
p.opts.mediaProxyHTTPClientTimeout = parseInt(value, defaultMediaProxyHTTPClientTimeout)
|
||||
p.opts.mediaProxyHTTPClientTimeout = parseInterval(value, time.Second, defaultMediaProxyHTTPClientTimeout)
|
||||
case "MEDIA_PROXY_MODE":
|
||||
p.opts.mediaProxyMode = parseString(value, defaultMediaProxyMode)
|
||||
case "MEDIA_PROXY_RESOURCE_TYPES":
|
||||
|
@ -206,7 +206,7 @@ func (p *parser) parseLines(lines []string) (err error) {
|
|||
case "DISABLE_LOCAL_AUTH":
|
||||
p.opts.disableLocalAuth = parseBool(value, defaultDisableLocalAuth)
|
||||
case "HTTP_CLIENT_TIMEOUT":
|
||||
p.opts.httpClientTimeout = parseInt(value, defaultHTTPClientTimeout)
|
||||
p.opts.httpClientTimeout = parseInterval(value, time.Second, defaultHTTPClientTimeout)
|
||||
case "HTTP_CLIENT_MAX_BODY_SIZE":
|
||||
p.opts.httpClientMaxBodySize = int64(parseInt(value, defaultHTTPClientMaxBodySize) * 1024 * 1024)
|
||||
case "HTTP_CLIENT_PROXY":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue