fix
This commit is contained in:
parent
6de13a61f7
commit
22f9bf7165
|
@ -104,14 +104,28 @@ type wsConnectItem struct {
|
|||
// 请求建立连接,升级websocket协议
|
||||
func (l *DataTransferLogic) DataTransfer(req *types.DataTransferReq, w http.ResponseWriter, r *http.Request) {
|
||||
//把子协议携带的token设置到标准token头信息中
|
||||
token := r.Header.Get("Sec-Websocket-Protocol")
|
||||
tokens := r.Header.Get("Sec-Websocket-Protocol")
|
||||
oldWid := req.Wid
|
||||
oldWid = strings.Trim(oldWid, " ")
|
||||
//有token是正常用户,无则是白板用户,也可以连接
|
||||
if token != "" {
|
||||
if tokens != "" {
|
||||
token := ""
|
||||
debugToken := ""
|
||||
tokenSlice := strings.Split(tokens, ",")
|
||||
switch len(tokenSlice) {
|
||||
case 1:
|
||||
token = strings.Trim(tokenSlice[0], " ")
|
||||
case 2:
|
||||
token = strings.Trim(tokenSlice[0], " ")
|
||||
debugToken = strings.Trim(tokenSlice[1], " ")
|
||||
r.Header.Set("Debug-Token", "Bearer "+debugToken)
|
||||
default:
|
||||
logx.Error("invalid ws token:", tokens)
|
||||
return
|
||||
}
|
||||
r.Header.Set("Authorization", "Bearer "+token)
|
||||
//设置Sec-Websocket-Protocol
|
||||
upgrader.Subprotocols = []string{token}
|
||||
upgrader.Subprotocols = []string{tokens}
|
||||
}
|
||||
//判断下是否火狐浏览器(获取浏览器第一条消息返回有收不到的bug需要延迟1秒)
|
||||
userAgent := r.Header.Get("User-Agent")
|
||||
|
|
Loading…
Reference in New Issue
Block a user