Skip to content

Commit

Permalink
Fix some simple issues found by staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
LK4D4 committed Oct 27, 2019
1 parent 0df2c85 commit 9032271
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 1 addition & 3 deletions libwebsocketd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 3 additions & 4 deletions libwebsocketd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 9032271

Please sign in to comment.