This commit is contained in:
laodaming 2023-08-23 12:29:59 +08:00
parent 41caa6db64
commit a72aa2feca

View File

@ -45,7 +45,7 @@ var (
},
}
//升级websocket
upgrade = websocket.Upgrader{
upgrader = websocket.Upgrader{
//最大可读取大小 10M
ReadBufferSize: 1024 * 10,
//握手超时时间15s
@ -86,9 +86,9 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
token := r.Header.Get("Sec-Websocket-Protocol")
r.Header.Set("Authorization", "Bearer "+token)
//设置Sec-Websocket-Protocol
upgrade.Subprotocols = []string{token}
upgrader.Subprotocols = []string{token}
//升级websocket
conn, err := upgrade.Upgrade(w, r, nil)
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
logx.Error("http upgrade websocket err:", err)
return