Commit 9401e3d1 authored by Jukka-Pekka Kekkonen's avatar Jukka-Pekka Kekkonen Committed by Russ Cox

websocket: fix missing Sec-WebSocket-Protocol on server response.

Due to header key normalization/typo, the server never responds with
the protocol header in place. This breaks all (draft76) applications
that are using the protocol-header.

R=ukai, rsc
CC=golang-dev
https://golang.org/cl/1969046
parent 3fc7f776
......@@ -133,7 +133,7 @@ func (f Handler) ServeHTTP(c *http.Conn, req *http.Request) {
buf.WriteString("Connection: Upgrade\r\n")
buf.WriteString("Sec-WebSocket-Location: " + location + "\r\n")
buf.WriteString("Sec-WebSocket-Origin: " + origin + "\r\n")
protocol, found := req.Header["Sec-WebSocket-Protocol"]
protocol, found := req.Header["Sec-Websocket-Protocol"]
if found {
buf.WriteString("Sec-WebSocket-Protocol: " + protocol + "\r\n")
}
......
......@@ -130,6 +130,23 @@ func TestWithQuery(t *testing.T) {
ws.Close()
}
func TestWithProtocol(t *testing.T) {
once.Do(startServer)
client, err := net.Dial("tcp", "", serverAddr)
if err != nil {
t.Fatal("dialing", err)
}
ws, err := newClient("/echo", "localhost", "http://localhost",
"ws://localhost/echo", "test", client, handshake)
if err != nil {
t.Errorf("WebSocket handshake: %v", err)
return
}
ws.Close()
}
func TestHTTP(t *testing.T) {
once.Do(startServer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment