From 3c8810287055d4f3133e246e7e80c7e4f48df817 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 22 Apr 2021 12:18:33 -0700 Subject: [PATCH] server: add idle timeout in http server configuration --- pkg/api/controller.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/api/controller.go b/pkg/api/controller.go index 40f9422b..c06c1fcb 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "os" + "time" "github.com/anuvu/zot/errors" ext "github.com/anuvu/zot/pkg/extensions" @@ -17,6 +18,10 @@ import ( "github.com/gorilla/mux" ) +const ( + idleTimeout = 120 * time.Second +) + type Controller struct { Config *Config Router *mux.Router @@ -60,7 +65,11 @@ func (c *Controller) Run() error { _ = NewRouteHandler(c) addr := fmt.Sprintf("%s:%s", c.Config.HTTP.Address, c.Config.HTTP.Port) - server := &http.Server{Addr: addr, Handler: c.Router} + server := &http.Server{ + Addr: addr, + Handler: c.Router, + IdleTimeout: idleTimeout, + } c.Server = server // Create the listener