From ee7af3f4172415f226364366b74e18acdae31022 Mon Sep 17 00:00:00 2001
From: Yordan Kinkov <yordan.kinkov@vereign.com>
Date: Fri, 14 Oct 2022 11:29:09 +0300
Subject: [PATCH] Add custom http client

---
 cmd/cache/main.go | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/cmd/cache/main.go b/cmd/cache/main.go
index c81842f..017494b 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,
+	}
+}
-- 
GitLab