diff options
author | Frédéric Guillot <fred@miniflux.net> | 2019-06-02 07:13:35 -0700 |
---|---|---|
committer | fguillot <fred@miniflux.net> | 2019-06-02 07:29:56 -0700 |
commit | bb720c87c191efe36a328d95a918f75df51d4976 (patch) | |
tree | 35b6e87ddf5c0b37208f489fd6680075f269a3ef /http | |
parent | 228862fefaa645026caa483ffe9993bf8c00b22e (diff) |
Make HTTP Client timeout and max body size configurable
Diffstat (limited to 'http')
-rw-r--r-- | http/client/client.go | 15 |
1 files changed, 4 insertions, 11 deletions
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}, |