From 9032271d6fbfe6997e13df526c460280509e5e5c Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Sun, 27 Oct 2019 06:55:14 +0000 Subject: [PATCH] Fix some simple issues found by staticcheck --- libwebsocketd/env.go | 4 +--- libwebsocketd/http.go | 7 +++---- main.go | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libwebsocketd/env.go b/libwebsocketd/env.go index 609063aa..10e71dc5 100644 --- a/libwebsocketd/env.go +++ b/libwebsocketd/env.go @@ -42,9 +42,7 @@ func createEnv(handler *WebsocketdHandler, req *http.Request, log *LogScope) []s env = appendEnv(env, "SERVER_SOFTWARE", handler.server.Config.ServerSoftware) parentStarts := len(env) - for _, v := range handler.server.Config.ParentEnv { - env = append(env, v) - } + env = append(env, handler.server.Config.ParentEnv...) // IMPORTANT ---> Adding a header? Make sure standardEnvCount (above) is up to date. diff --git a/libwebsocketd/http.go b/libwebsocketd/http.go index 77f83b1a..378946a4 100644 --- a/libwebsocketd/http.go +++ b/libwebsocketd/http.go @@ -71,7 +71,7 @@ func (h *WebsocketdServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { if h.Config.CommandName != "" || h.Config.UsingScriptDir { hdrs := req.Header - upgradeRe := regexp.MustCompile("(?i)(^|[,\\s])Upgrade($|[,\\s])") + upgradeRe := regexp.MustCompile(`(?i)(^|[,\s])Upgrade($|[,\s])`) // WebSocket, limited to size of h.forks if strings.ToLower(hdrs.Get("Upgrade")) == "websocket" && upgradeRe.MatchString(hdrs.Get("Connection")) { if h.noteForkCreated() == nil { @@ -118,7 +118,7 @@ func (h *WebsocketdServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { } else { log.Error("http", "Max of possible forks already active, upgrade rejected") - http.Error(w, "429 Too Many Requests", 429) + http.Error(w, "429 Too Many Requests", http.StatusTooManyRequests) } return } @@ -162,7 +162,7 @@ func (h *WebsocketdServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { cgiHandler.ServeHTTP(w, req) } else { log.Error("http", "Fork not allowed since maxforks amount has been reached. CGI was not run.") - http.Error(w, "429 Too Many Requests", 429) + http.Error(w, "429 Too Many Requests", http.StatusTooManyRequests) } return } @@ -228,7 +228,6 @@ func (h *WebsocketdServer) noteForkCompled() { panic("Cannot deplet number of allowed forks, something is not right in code!") } } - return } func checkOrigin(req *http.Request, config *Config, log *LogScope) (err error) { diff --git a/main.go b/main.go index 20d902fe..ec09496b 100644 --- a/main.go +++ b/main.go @@ -109,8 +109,8 @@ func main() { }(addrSingle) } } - select { - case err := <-rejects: + err := <-rejects + if err != nil { log.Fatal("server", "Can't start server: %s", err) os.Exit(3) }