]> Cypherpunks repositories - gostls13.git/commitdiff
websocket: fix missing Sec-WebSocket-Protocol on server response.
authorJukka-Pekka Kekkonen <karatepekka@gmail.com>
Wed, 25 Aug 2010 16:52:04 +0000 (12:52 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 25 Aug 2010 16:52:04 +0000 (12:52 -0400)
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

src/pkg/websocket/server.go
src/pkg/websocket/websocket_test.go

index b58ad122b7c8798862c10165ab3a6b61e9abf7c8..6f33a9abed540962325c661d584d4840390b65f3 100644 (file)
@@ -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")
        }
index 22aa1fa5be7be22bd9519f8b30d415b5e457973d..4cd84617c7ece463186388151ceb3ab77820aebc 100644 (file)
@@ -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)