From 2011a3191c814ed976b05cb44aa7e9277383422c Mon Sep 17 00:00:00 2001 From: 0xff-dev Date: Thu, 13 Jul 2023 16:55:46 +0800 Subject: [PATCH] chore: HTTPGetter add default timeout Signed-off-by: 0xff-dev Co-authored-by: bjwswang Co-authored-by: Abirdcfly --- pkg/getter/getter.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/getter/getter.go b/pkg/getter/getter.go index 653b032fe..3ba72ccde 100644 --- a/pkg/getter/getter.go +++ b/pkg/getter/getter.go @@ -172,9 +172,21 @@ func (p Providers) ByScheme(scheme string) (Getter, error) { return nil, errors.Errorf("scheme %q not supported", scheme) } +const ( + // The cost timeout references curl's default connection timeout. + // https://github.com/curl/curl/blob/master/lib/connect.h#L40C21-L40C21 + // The helm commands are usually executed manually. Considering the acceptable waiting time, we reduced the entire request time to 120s. + DefaultHTTPTimeout = 120 +) + +var defaultOptions = []Option{WithTimeout(time.Second * DefaultHTTPTimeout)} + var httpProvider = Provider{ Schemes: []string{"http", "https"}, - New: NewHTTPGetter, + New: func(options ...Option) (Getter, error) { + options = append(options, defaultOptions...) + return NewHTTPGetter(options...) + }, } var ociProvider = Provider{