mirror of
https://github.com/golang/go
synced 2024-11-12 05:50:21 -07:00
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
This commit is contained in:
parent
3fc7f776d3
commit
9401e3d1e4
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user