summaryrefslogtreecommitdiff
path: root/client/httpclient.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/httpclient.go')
-rw-r--r--client/httpclient.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/client/httpclient.go b/client/httpclient.go
index bd00b6b..fe6e2e5 100644
--- a/client/httpclient.go
+++ b/client/httpclient.go
@@ -13,6 +13,7 @@ import (
"strings"
"time"
+ "github.com/hashicorp/go-retryablehttp"
"gitlab.com/gitlab-org/labkit/correlation"
"gitlab.com/gitlab-org/labkit/tracing"
)
@@ -25,13 +26,12 @@ const (
defaultReadTimeoutSeconds = 300
)
-var (
- ErrCafileNotFound = errors.New("cafile not found")
-)
+var ErrCafileNotFound = errors.New("cafile not found")
type HttpClient struct {
- *http.Client
- Host string
+ HTTPClient *http.Client
+ RetryableHTTP *retryablehttp.Client
+ Host string
}
type httpClientCfg struct {
@@ -106,7 +106,22 @@ func NewHTTPClientWithOpts(gitlabURL, gitlabRelativeURLRoot, caFile, caPath stri
Timeout: readTimeout(readTimeoutSeconds),
}
- client := &HttpClient{Client: c, Host: host}
+ client := &HttpClient{HTTPClient: c, Host: host}
+
+ if os.Getenv("FF_GITLAB_SHELL_RETRYABLE_HTTP") == "1" {
+ c := retryablehttp.NewClient()
+ c.RetryMax = 2
+ c.RetryWaitMax = 15 * time.Second
+ c.Logger = nil
+ c.HTTPClient.Transport = correlation.NewInstrumentedRoundTripper(tracing.NewRoundTripper(transport))
+ c.HTTPClient.Timeout = readTimeout(readTimeoutSeconds)
+
+ client = &HttpClient{RetryableHTTP: c, Host: host}
+ }
+
+ if client.HTTPClient == nil && client.RetryableHTTP == nil {
+ panic("client/httpclient.go did not set http client")
+ }
return client, nil
}
@@ -132,7 +147,6 @@ func buildSocketTransport(gitlabURL, gitlabRelativeURLRoot string) (*http.Transp
func buildHttpsTransport(hcc httpClientCfg, gitlabURL string) (*http.Transport, string, error) {
certPool, err := x509.SystemCertPool()
-
if err != nil {
certPool = x509.NewCertPool()
}