This commit is contained in:
laodaming 2023-08-18 17:52:19 +08:00
parent 75aacbcc65
commit 5c7d1bb6b0

View File

@ -81,9 +81,10 @@ type wsConnectItem struct {
// 请求建立连接升级websocket协议
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
//把子协议携带的token设置到标准token头信息中
r.Header.Set("Authorization", "Bearer "+r.Header.Get("Sec-Websocket-Protocol"))
token := r.Header.Get("Sec-Websocket-Protocol")
r.Header.Set("Authorization", "Bearer "+token)
//设置Sec-Websocket-Protocol
upgrade.Subprotocols = []string{r.Header.Get("Sec-Websocket-Protocol")}
upgrade.Subprotocols = []string{token}
//升级websocket
conn, err := upgrade.Upgrade(w, r, nil)
if err != nil {