Skip to content

Commit

Permalink
feat: net/http/httputilmore: add NewServerTimeouts()
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Oct 29, 2023
1 parent 4e72071 commit 108f6a6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions net/http/httputilmore/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package httputilmore
import (
"log"
"net/http"
"time"
)

// Log is a custom Http handler that will log all requests.
Expand All @@ -15,3 +16,16 @@ func Log(handler http.Handler) http.Handler {
handler.ServeHTTP(w, r)
})
}

// NewServerTimeouts returns a `*http.Server` with all timeouts set to a single value provided.
func NewServerTimeouts(addr string, handler http.Handler, timeout time.Duration) *http.Server {
return &http.Server{
Addr: addr,
Handler: handler,
IdleTimeout: timeout,
ReadHeaderTimeout: timeout,
ReadTimeout: timeout,
WriteTimeout: timeout,
MaxHeaderBytes: 1 << 20,
}
}

0 comments on commit 108f6a6

Please sign in to comment.