websocket: Avoid multiple calls to WriteHeader if Upgrade fails

This commit is contained in:
Matthew Holt 2017-09-22 17:39:18 -06:00
parent 643dac688c
commit 64be3e410c
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -86,7 +86,9 @@ func serveWS(w http.ResponseWriter, r *http.Request, config *Config) (int, error
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return http.StatusBadRequest, err
// the connection has been "handled" -- WriteHeader was called with Upgrade,
// so don't return an error status code; just return an error
return 0, err
}
defer conn.Close()