From bb720c87c191efe36a328d95a918f75df51d4976 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 2 Jun 2019 07:13:35 -0700 Subject: Make HTTP Client timeout and max body size configurable --- http/client/client.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'http/client') diff --git a/http/client/client.go b/http/client/client.go index 2dce15c..175fe9f 100644 --- a/http/client/client.go +++ b/http/client/client.go @@ -18,20 +18,13 @@ import ( "strings" "time" + "miniflux.app/config" "miniflux.app/errors" "miniflux.app/logger" "miniflux.app/timer" "miniflux.app/version" ) -const ( - // 20 seconds max. - requestTimeout = 20 - - // 15MB max. - maxBodySize = 1024 * 1024 * 15 -) - var ( // DefaultUserAgent sets the User-Agent header used for any requests by miniflux. DefaultUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)" @@ -144,7 +137,7 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) { case net.Error: nerr := uerr.Err.(net.Error) if nerr.Timeout() { - err = errors.NewLocalizedError(errRequestTimeout, requestTimeout) + err = errors.NewLocalizedError(errRequestTimeout, config.Opts.HTTPClientTimeout()) } else if nerr.Temporary() { err = errors.NewLocalizedError(errTemporaryNetworkOperation, nerr) } @@ -154,7 +147,7 @@ func (c *Client) executeRequest(request *http.Request) (*Response, error) { return nil, err } - if resp.ContentLength > maxBodySize { + if resp.ContentLength > config.Opts.HTTPClientMaxBodySize() { return nil, fmt.Errorf("client: response too large (%d bytes)", resp.ContentLength) } @@ -212,7 +205,7 @@ func (c *Client) buildRequest(method string, body io.Reader) (*http.Request, err } func (c *Client) buildClient() http.Client { - client := http.Client{Timeout: time.Duration(requestTimeout * time.Second)} + client := http.Client{Timeout: time.Duration(config.Opts.HTTPClientTimeout()) * time.Second} if c.Insecure { client.Transport = &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, -- cgit v1.2.3