Skip to content

Commit

Permalink
address comment 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Jul 15, 2022
1 parent 8410dee commit 812113f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ 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
}
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,
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/httputil/httputil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down

0 comments on commit 812113f

Please sign in to comment.