我正在尝试设置Cookie,有时它有效,有时它不起作用。没有明显的模式。
func quoteGetHandler(w http.ResponseWriter, req *http.Request) {
parts := strings.Split(req.URL.Path, "/")
csrfToken := uniuri.NewLen(32)
exp, err := strconv.Atoi(os.Getenv("COOKIE_EXPIRE")) //5
if err != nil {
http.Error(w, whereami.WhereAmI()+err.Error(), http.StatusInternalServerError)
}
expire := time.Now().Add(time.Duration(exp) * time.Minute)
cookie := http.Cookie{
Name: os.Getenv("COOKIE_NAME"), //csrf_token
Value: csrfToken, //string
Path: "/",
Expires: expire,
HttpOnly: true,
Secure: true,
MaxAge: 0,
Domain: os.Getenv("DOMAIN")} //<--example.com
http.SetCookie(w, &cookie)
tmp := htmlTags["quote"]
tmp.CsrfToken = csrfToken
if 2 < len(parts) && parts[2] != "" {
tmp.Param = parts[2]
}
htmlTags["quote"] = tmp
err = tmpl.ExecuteTemplate(w, siteType+"quote", htmlTags["quote"])
if err != nil {
http.Error(w, whereami.WhereAmI()+err.Error(), http.StatusInternalServerError)
}
}
这发生在Chrome,FF,Bravo,Safari上。
协议是 https。
慕桂英4014372
相关分类