fix
This commit is contained in:
parent
04982bae18
commit
b8ca7360b1
|
@ -80,9 +80,9 @@ type wsConnectItem struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
|
func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) {
|
||||||
token := r.Header.Get("Sec-Websocket-Protocol")
|
r.Header.Set("Authorization", "Bearer "+r.Header.Get("Sec-Websocket-Protocol"))
|
||||||
//设置Sec-Websocket-Protocol
|
//设置Sec-Websocket-Protocol
|
||||||
upgrade.Subprotocols = []string{token}
|
upgrade.Subprotocols = []string{r.Header.Get("Sec-Websocket-Protocol")}
|
||||||
//升级websocket
|
//升级websocket
|
||||||
conn, err := upgrade.Upgrade(w, r, nil)
|
conn, err := upgrade.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,7 +95,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
||||||
userInfo *auth.UserInfo
|
userInfo *auth.UserInfo
|
||||||
isAuth bool
|
isAuth bool
|
||||||
)
|
)
|
||||||
fmt.Println("###################:", r.Header)
|
|
||||||
isAuth, userInfo = l.checkAuth(r)
|
isAuth, userInfo = l.checkAuth(r)
|
||||||
if !isAuth {
|
if !isAuth {
|
||||||
time.Sleep(time.Second * 1) //兼容下火狐
|
time.Sleep(time.Second * 1) //兼容下火狐
|
||||||
|
@ -182,6 +181,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||||
claims, err := l.svcCtx.ParseJwtToken(r)
|
claims, err := l.svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
if claims != nil {
|
if claims != nil {
|
||||||
|
@ -189,6 +189,7 @@ func (l *DataTransferLogic) checkAuth(r *http.Request) (isAuth bool, userInfo *a
|
||||||
userInfo, err = auth.GetUserInfoFormMapClaims(claims)
|
userInfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
//不是登录用户也不是游客
|
//不是登录用户也不是游客
|
||||||
|
|
Loading…
Reference in New Issue
Block a user