mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
fix issue in session for ghttp.Server
This commit is contained in:
@ -16,6 +16,9 @@ func main() {
|
||||
s.BindHandler("/get", func(r *ghttp.Request) {
|
||||
r.Response.WriteJson(r.Session.Map())
|
||||
})
|
||||
s.BindHandler("/clear", func(r *ghttp.Request) {
|
||||
r.Session.Clear()
|
||||
})
|
||||
s.SetPort(8199)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
2
go.sum
2
go.sum
@ -10,6 +10,7 @@ github.com/gf-third/mysql v1.4.2 h1:f1M5CNFUG3WkE07UOomtu4o0n/KJKeuUUf5Nc9ZFXs4=
|
||||
github.com/gf-third/mysql v1.4.2/go.mod h1:+dd90V663ppI2fV5uQ6+rHk0u8KCyU6FkG8Um8Cx3ms=
|
||||
github.com/gofrs/flock v0.7.1 h1:DP+LD/t0njgoPBvT5MJLeliUIVQR03hiKR6vezdwHlc=
|
||||
github.com/gofrs/flock v0.7.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
@ -27,6 +28,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
||||
@ -141,6 +141,7 @@ func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// 设置Session Id到Cookie中
|
||||
if request.Session.Id() != "" && request.GetSessionId() != request.Session.Id() {
|
||||
request.Response.Header().Set(s.GetSessionIdName(), request.Session.Id())
|
||||
request.Cookie.SetSessionId(request.Session.Id())
|
||||
}
|
||||
// 输出Cookie
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// COOKIE测试
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
|
||||
@ -129,7 +129,7 @@ func (s *Session) Clear() {
|
||||
// UpdateTTL updates the ttl of the session.
|
||||
// If this session is dirty, it also exports it to storage.
|
||||
func (s *Session) UpdateTTL() {
|
||||
if len(s.id) > 0 && s.data != nil && s.data.Size() > 0 {
|
||||
if len(s.id) > 0 && s.data != nil {
|
||||
if s.manager.storage != nil {
|
||||
if s.dirty.Cas(true, false) {
|
||||
s.data.RLockFunc(func(m map[string]interface{}) {
|
||||
|
||||
@ -50,7 +50,9 @@ func NewStorageFile(ttl time.Duration, path ...string) *StorageFile {
|
||||
if len(path) > 0 && path[0] != "" {
|
||||
storagePath, _ = gfile.Search(path[0])
|
||||
if storagePath == "" {
|
||||
glog.Panicf("'%s' does not exist", path[0])
|
||||
if err := gfile.Mkdir(storagePath); err != nil {
|
||||
glog.Panicf("mkdir '%s' failed: %v", path[0], err)
|
||||
}
|
||||
}
|
||||
if !gfile.IsWritable(storagePath) {
|
||||
glog.Panicf("'%s' is not writable", path[0])
|
||||
|
||||
Reference in New Issue
Block a user