Commit 726e59c5 authored by Cédric OLIVIER's avatar Cédric OLIVIER
Browse files

Merge branch 'fix-lint-issue' into 'master'

fix: linter issue related to G112: Potential Slowloris Attack

See merge request to-be-continuous/tools/tracking!30
parents 8b96a052 38126d6b
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -23,12 +23,15 @@ import (
	"log"
	"net/http"
	"strings"
	"time"
)

type healthResponse struct {
	Status string `json:"status"`
}

const readHeaderTimeout = 2 * time.Second

func serverHandler(writer http.ResponseWriter, request *http.Request) {
	if strings.ToUpper(request.Method) != "GET" {
		http.Error(writer, "Method not allowed", http.StatusMethodNotAllowed)
@@ -54,6 +57,10 @@ func health(writer http.ResponseWriter, request *http.Request) {

func HealthService(port int) (error, *http.Server) {
	log.Printf("Starting application on port %d\n", port)
	server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: http.HandlerFunc(serverHandler)}
	server := &http.Server{
		Addr:              fmt.Sprintf(":%d", port),
		Handler:           http.HandlerFunc(serverHandler),
		ReadHeaderTimeout: readHeaderTimeout,
	}
	return server.ListenAndServe(), server
}