From 812113fde7660a79f4f17274ec10d04005e175f5 Mon Sep 17 00:00:00 2001 From: Dustin Xie Date: Fri, 15 Jul 2022 10:12:27 -0700 Subject: [PATCH] address comment 2 --- api/http.go | 3 +-- pkg/util/httputil/httputil.go | 4 ++-- pkg/util/httputil/httputil_test.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/api/http.go b/api/http.go index 449cd71775..f652fa336c 100644 --- a/api/http.go +++ b/api/http.go @@ -27,7 +27,6 @@ type ( ) // NewHTTPServer creates a new http server -// TODO: move timeout into config func NewHTTPServer(route string, port int, handler http.Handler) *HTTPServer { if port == 0 { return nil @@ -35,7 +34,7 @@ func NewHTTPServer(route string, port int, handler http.Handler) *HTTPServer { mux := http.NewServeMux() mux.Handle("/"+route, handler) - svr := httputil.NewServer(":"+strconv.Itoa(port), mux, httputil.HeaderTimeout(10*time.Second)) + svr := httputil.NewServer(":"+strconv.Itoa(port), mux, httputil.ReadHeaderTimeout(10*time.Second)) return &HTTPServer{ svr: &svr, } diff --git a/pkg/util/httputil/httputil.go b/pkg/util/httputil/httputil.go index 15ccebcfd5..5d3aa63194 100644 --- a/pkg/util/httputil/httputil.go +++ b/pkg/util/httputil/httputil.go @@ -32,8 +32,8 @@ var DefaultServerConfig = serverConfig{ IdleTimeout: 120 * time.Second, } -// HeaderTimeout sets header timeout -func HeaderTimeout(h time.Duration) ServerOption { +// ReadHeaderTimeout sets header timeout +func ReadHeaderTimeout(h time.Duration) ServerOption { return func(cfg *serverConfig) { cfg.ReadHeaderTimeout = h } diff --git a/pkg/util/httputil/httputil_test.go b/pkg/util/httputil/httputil_test.go index bc40aa4ff9..2c98dc9b78 100644 --- a/pkg/util/httputil/httputil_test.go +++ b/pkg/util/httputil/httputil_test.go @@ -22,7 +22,7 @@ func TestServer(t *testing.T) { Addr: addr, Handler: handler, } - result := NewServer(addr, handler, HeaderTimeout(2*time.Second)) + result := NewServer(addr, handler, ReadHeaderTimeout(2*time.Second)) require.Equal(t, expectValue, result) }) }