Skip to content

Commit

Permalink
feat: default http client timeout override
Browse files Browse the repository at this point in the history
  • Loading branch information
or-shachar committed Oct 26, 2023
1 parent c16c285 commit 26fb5a6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"os"
"strings"
"time"

Expand All @@ -16,6 +17,8 @@ import (
"github.com/CircleCI-Public/circleci-cli/version"
)

const defaultTimeout = 10 * time.Second

type Client struct {
BaseURL *url.URL
circleToken string
Expand All @@ -38,9 +41,17 @@ func NewFromConfig(host string, config *settings.Config) *Client {
}

baseURL, _ := url.Parse(host)
timeout := defaultTimeout
if timeoutEnv, ok := os.LookupEnv("HTTP_TIMEOUT"); ok {
if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil {
timeout = parsedTimeout
} else {
fmt.Printf("failed to parse HTTP_TIMEOUT_SECONDS: %s\n", err.Error())
}
}

client := config.HTTPClient
client.Timeout = 10 * time.Second
client.Timeout = timeout

return New(
baseURL.ResolveReference(&url.URL{Path: endpoint}),
Expand Down

0 comments on commit 26fb5a6

Please sign in to comment.