diff --git a/cmd/cache/main.go b/cmd/cache/main.go index c81842f9d285d0738bc99486eb6fdc49552a8cea..017494bd919a3e4ddad29eceeb01ff937b5a90c2 100644 --- a/cmd/cache/main.go +++ b/cmd/cache/main.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "net" "net/http" "time" @@ -106,7 +107,7 @@ func main() { // Apply Authentication middleware if enabled if cfg.Auth.Enabled { - m, err := auth.NewMiddleware(cfg.Auth.JwkURL, cfg.Auth.RefreshInterval, http.DefaultClient) + m, err := auth.NewMiddleware(cfg.Auth.JwkURL, cfg.Auth.RefreshInterval, httpClient()) if err != nil { log.Fatalf("failed to create authentication middleware: %v", err) } @@ -174,3 +175,19 @@ func exposeMetrics(addr string, logger *zap.Logger) { logger.Error("error exposing prometheus metrics", zap.Error(err)) } } + +func httpClient() *http.Client { + return &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + }).DialContext, + MaxIdleConns: 100, + MaxIdleConnsPerHost: 100, + TLSHandshakeTimeout: 10 * time.Second, + IdleConnTimeout: 60 * time.Second, + }, + Timeout: 30 * time.Second, + } +}