From 64be3e410c3828dc6250c12b401d41f2d7e8ea0b Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 22 Sep 2017 17:39:18 -0600 Subject: [PATCH] websocket: Avoid multiple calls to WriteHeader if Upgrade fails --- caddyhttp/websocket/websocket.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/caddyhttp/websocket/websocket.go b/caddyhttp/websocket/websocket.go index 3bead97b0..a0188bd4a 100644 --- a/caddyhttp/websocket/websocket.go +++ b/caddyhttp/websocket/websocket.go @@ -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()