Skip to content

Commit b11e4ec

Browse files
committed
Improve handshake to better match RFC
Closes #176 Closes #173
1 parent cb50d97 commit b11e4ec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

handshake.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ func verifyClientRequest(w http.ResponseWriter, r *http.Request) error {
5555
}
5656

5757
if !headerValuesContainsToken(r.Header, "Connection", "Upgrade") {
58+
w.Header().Set("Connection", "Upgrade")
59+
w.Header().Set("Upgrade", "websocket")
5860
err := fmt.Errorf("websocket protocol violation: Connection header %q does not contain Upgrade", r.Header.Get("Connection"))
59-
http.Error(w, err.Error(), http.StatusBadRequest)
61+
http.Error(w, err.Error(), http.StatusUpgradeRequired)
6062
return err
6163
}
6264

6365
if !headerValuesContainsToken(r.Header, "Upgrade", "WebSocket") {
66+
w.Header().Set("Connection", "Upgrade")
67+
w.Header().Set("Upgrade", "websocket")
6468
err := fmt.Errorf("websocket protocol violation: Upgrade header %q does not contain websocket", r.Header.Get("Upgrade"))
65-
http.Error(w, err.Error(), http.StatusBadRequest)
69+
http.Error(w, err.Error(), http.StatusUpgradeRequired)
6670
return err
6771
}
6872

@@ -73,6 +77,7 @@ func verifyClientRequest(w http.ResponseWriter, r *http.Request) error {
7377
}
7478

7579
if r.Header.Get("Sec-WebSocket-Version") != "13" {
80+
w.Header().Set("Sec-WebSocket-Version", "13")
7681
err := fmt.Errorf("unsupported websocket protocol version (only 13 is supported): %q", r.Header.Get("Sec-WebSocket-Version"))
7782
http.Error(w, err.Error(), http.StatusBadRequest)
7883
return err

0 commit comments

Comments
 (0)