Skip to content

Commit 1a41486

Browse files
authored
fix: websocket conns do not require Connection: upgrade header (#161)
It turns out that the WebSocket API provided by browsers [1] does not actually send the `Connection: upgrade` header that our websocket implementation (wrongly?) requires, so here we're dropping that requirement. [1]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
1 parent 21c68b8 commit 1a41486

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

httpbin/websocket/websocket.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ func (s *WebSocket) Handshake() error {
115115
panic("websocket: handshake already completed")
116116
}
117117

118-
if strings.ToLower(s.r.Header.Get("Connection")) != "upgrade" {
119-
return fmt.Errorf("missing required `Connection: upgrade` header")
120-
}
121118
if strings.ToLower(s.r.Header.Get("Upgrade")) != "websocket" {
122119
return fmt.Errorf("missing required `Upgrade: websocket` header")
123120
}

httpbin/websocket/websocket_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ func TestHandshake(t *testing.T) {
5151
},
5252
wantStatus: http.StatusSwitchingProtocols,
5353
},
54-
"missing Connection header": {
54+
"missing Connection header is okay": {
5555
reqHeaders: map[string]string{
5656
"Upgrade": "websocket",
5757
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
5858
"Sec-WebSocket-Version": "13",
5959
},
60-
wantStatus: http.StatusBadRequest,
60+
wantStatus: http.StatusSwitchingProtocols,
6161
},
62-
"incorrect Connection header": {
62+
"incorrect Connection header is also okay": {
6363
reqHeaders: map[string]string{
64-
"Connection": "close",
64+
"Connection": "foo",
6565
"Upgrade": "websocket",
6666
"Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==",
6767
"Sec-WebSocket-Version": "13",
6868
},
69-
wantStatus: http.StatusBadRequest,
69+
wantStatus: http.StatusSwitchingProtocols,
7070
},
7171
"missing Upgrade header": {
7272
reqHeaders: map[string]string{

0 commit comments

Comments
 (0)