ocr增加

This commit is contained in:
hoteas 2021-12-09 11:16:15 +08:00
parent af726fbcfb
commit 0e33c2ad9d

View File

@ -295,11 +295,14 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
cookie, err := req.Cookie(that.Config.GetString("sessionName")) cookie, err := req.Cookie(that.Config.GetString("sessionName"))
sessionId := Md5(strconv.Itoa(Rand(10))) sessionId := Md5(strconv.Itoa(Rand(10)))
token := req.FormValue("token") token := req.FormValue("token")
if len(token) != 32 {
if err != nil || (len(token) == 32 && cookie.Value != token) { token = req.Header.Get("Authorization")
if len(token) == 32 {
sessionId = token
} }
if len(token) == 32 && cookie.Value != token {
sessionId = token
} else {
sessionId = cookie.Value
//没有跨域设置 //没有跨域设置
if that.Config.GetString("crossDomain") == "" { if that.Config.GetString("crossDomain") == "" {
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"}) 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才有效果 //跨域允许需要设置cookie的允许跨域https才有效果
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure") w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
} }
} else {
sessionId = cookie.Value
} }
unescapeUrl, err := url.QueryUnescape(req.RequestURI) unescapeUrl, err := url.QueryUnescape(req.RequestURI)