From 0e33c2ad9dc27c2c7f403f46cfff2748f11c4c6b Mon Sep 17 00:00:00 2001 From: hoteas Date: Thu, 9 Dec 2021 11:16:15 +0800 Subject: [PATCH] =?UTF-8?q?ocr=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/application.go b/application.go index c221de1..71ae556 100644 --- a/application.go +++ b/application.go @@ -295,11 +295,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { cookie, err := req.Cookie(that.Config.GetString("sessionName")) sessionId := Md5(strconv.Itoa(Rand(10))) token := req.FormValue("token") + if len(token) != 32 { + token = req.Header.Get("Authorization") + } - if err != nil || (len(token) == 32 && cookie.Value != token) { - if len(token) == 32 { - sessionId = token - } + if len(token) == 32 && cookie.Value != token { + sessionId = token + } else { + sessionId = cookie.Value //没有跨域设置 if that.Config.GetString("crossDomain") == "" { http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"}) @@ -307,8 +310,7 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { //跨域允许需要设置cookie的允许跨域https才有效果 w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure") } - } else { - sessionId = cookie.Value + } unescapeUrl, err := url.QueryUnescape(req.RequestURI)