Skip to content

Commit 21ab95f

Browse files
authored
Modify headers to match case used in RFC examples
Change the subprotocol and extension header names to match the case used in RFC examples. Other headers names already match the case used in the examples. Although the headers names in the handshake are case insensitive, some libraries expect the exact case used in the RFC examples. This change allows the package to interoperate with those broken libraries.
1 parent cd94665 commit 21ab95f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
201201
}
202202

203203
if d.EnableCompression {
204-
req.Header.Set("Sec-Websocket-Extensions", "permessage-deflate; server_no_context_takeover; client_no_context_takeover")
204+
req.Header["Sec-WebSocket-Extensions"] = []string{"permessage-deflate; server_no_context_takeover; client_no_context_takeover"}
205205
}
206206

207207
var deadline time.Time

server.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header
103103
//
104104
// The responseHeader is included in the response to the client's upgrade
105105
// request. Use the responseHeader to specify cookies (Set-Cookie) and the
106-
// application negotiated subprotocol (Sec-Websocket-Protocol).
106+
// application negotiated subprotocol (Sec-WebSocket-Protocol).
107107
//
108108
// If the upgrade fails, then Upgrade replies to the client with an HTTP error
109109
// response.
@@ -127,7 +127,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
127127
}
128128

129129
if _, ok := responseHeader["Sec-Websocket-Extensions"]; ok {
130-
return u.returnError(w, r, http.StatusInternalServerError, "websocket: application specific 'Sec-Websocket-Extensions' headers are unsupported")
130+
return u.returnError(w, r, http.StatusInternalServerError, "websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported")
131131
}
132132

133133
checkOrigin := u.CheckOrigin
@@ -140,7 +140,7 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
140140

141141
challengeKey := r.Header.Get("Sec-Websocket-Key")
142142
if challengeKey == "" {
143-
return u.returnError(w, r, http.StatusBadRequest, "websocket: not a websocket handshake: `Sec-Websocket-Key' header is missing or blank")
143+
return u.returnError(w, r, http.StatusBadRequest, "websocket: not a websocket handshake: `Sec-WebSocket-Key' header is missing or blank")
144144
}
145145

146146
subprotocol := u.selectSubprotocol(r, responseHeader)
@@ -190,12 +190,12 @@ func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeade
190190
p = append(p, computeAcceptKey(challengeKey)...)
191191
p = append(p, "\r\n"...)
192192
if c.subprotocol != "" {
193-
p = append(p, "Sec-Websocket-Protocol: "...)
193+
p = append(p, "Sec-WebSocket-Protocol: "...)
194194
p = append(p, c.subprotocol...)
195195
p = append(p, "\r\n"...)
196196
}
197197
if compress {
198-
p = append(p, "Sec-Websocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover\r\n"...)
198+
p = append(p, "Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover\r\n"...)
199199
}
200200
for k, vs := range responseHeader {
201201
if k == "Sec-Websocket-Protocol" {

0 commit comments

Comments
 (0)