1
0
Fork 0
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:
gudvinr 2025-08-18 23:10:18 +03:00 committed by Frédéric Guillot
parent 71af68becd
commit 30453ad7ec
5 changed files with 51 additions and 22 deletions

View file

@ -18,14 +18,14 @@ import (
)
const (
defaultHTTPClientTimeout = 20
defaultHTTPClientTimeout = 20 * time.Second
defaultAcceptHeader = "application/xml, application/atom+xml, application/rss+xml, application/rdf+xml, application/feed+json, text/html, */*;q=0.9"
)
type RequestBuilder struct {
headers http.Header
clientProxyURL *url.URL
clientTimeout int
clientTimeout time.Duration
useClientProxy bool
withoutRedirects bool
ignoreTLSErrors bool
@ -104,7 +104,7 @@ func (r *RequestBuilder) WithCustomFeedProxyURL(proxyURL string) *RequestBuilder
return r
}
func (r *RequestBuilder) WithTimeout(timeout int) *RequestBuilder {
func (r *RequestBuilder) WithTimeout(timeout time.Duration) *RequestBuilder {
r.clientTimeout = timeout
return r
}
@ -185,7 +185,7 @@ func (r *RequestBuilder) ExecuteRequest(requestURL string) (*http.Response, erro
}
client := &http.Client{
Timeout: time.Duration(r.clientTimeout) * time.Second,
Timeout: r.clientTimeout,
}
if r.withoutRedirects {

View file

@ -232,9 +232,9 @@ func TestRequestBuilder_CustomAcceptHeaderNotOverridden(t *testing.T) {
func TestRequestBuilder_WithTimeout(t *testing.T) {
builder := NewRequestBuilder()
builder = builder.WithTimeout(30)
builder = builder.WithTimeout(30 * time.Second)
if builder.clientTimeout != 30 {
if builder.clientTimeout != 30*time.Second {
t.Errorf("Expected timeout to be 30, got %d", builder.clientTimeout)
}
}
@ -382,9 +382,8 @@ func TestRequestBuilder_ChainedMethods(t *testing.T) {
WithUserAgent("TestAgent/1.0", "DefaultAgent/1.0").
WithCookie("test=value").
WithETag("etag123").
WithTimeout(10).
WithTimeout(10 * time.Second).
ExecuteRequest(server.URL)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
@ -409,7 +408,7 @@ func TestRequestBuilder_TimeoutConfiguration(t *testing.T) {
builder := NewRequestBuilder()
start := time.Now()
_, err := builder.WithTimeout(1).ExecuteRequest(server.URL)
_, err := builder.WithTimeout(1 * time.Second).ExecuteRequest(server.URL)
duration := time.Since(start)
if err == nil {