mirror of https://github.com/gorilla/websocket.git
When sending a Close frame in response, the endpoint typically echos the status code it received.
This commit is contained in:
parent
b824a5d853
commit
bf696496cb
4
conn.go
4
conn.go
|
@ -726,13 +726,15 @@ func (c *Conn) advanceFrame() (int, error) {
|
||||||
return noFrame, err
|
return noFrame, err
|
||||||
}
|
}
|
||||||
case CloseMessage:
|
case CloseMessage:
|
||||||
c.WriteControl(CloseMessage, []byte{}, time.Now().Add(writeWait))
|
echoMessage := []byte{}
|
||||||
closeCode := CloseNoStatusReceived
|
closeCode := CloseNoStatusReceived
|
||||||
closeText := ""
|
closeText := ""
|
||||||
if len(payload) >= 2 {
|
if len(payload) >= 2 {
|
||||||
|
echoMessage = payload[:2]
|
||||||
closeCode = int(binary.BigEndian.Uint16(payload))
|
closeCode = int(binary.BigEndian.Uint16(payload))
|
||||||
closeText = string(payload[2:])
|
closeText = string(payload[2:])
|
||||||
}
|
}
|
||||||
|
c.WriteControl(CloseMessage, echoMessage, time.Now().Add(writeWait))
|
||||||
return noFrame, &CloseError{Code: closeCode, Text: closeText}
|
return noFrame, &CloseError{Code: closeCode, Text: closeText}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue