Procházet zdrojové kódy

vendor: update github.com/go-macaron/session

Unknwon před 5 roky
rodič
revize
458aadbb10

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.11.75.1203
+0.11.76.1204

+ 5 - 0
vendor/github.com/go-macaron/session/file.go

@@ -81,6 +81,11 @@ func (s *FileStore) Release() error {
 	s.p.lock.Lock()
 	defer s.p.lock.Unlock()
 
+	// Skip encoding if the data is empty
+	if len(s.data) == 0 {
+		return nil
+	}
+
 	data, err := EncodeGob(s.data)
 	if err != nil {
 		return err

+ 5 - 0
vendor/github.com/go-macaron/session/redis/redis.go

@@ -81,6 +81,11 @@ func (s *RedisStore) ID() string {
 
 // Release releases resource and save data to provider.
 func (s *RedisStore) Release() error {
+	// Skip encoding if the data is empty
+	if len(s.data) == 0 {
+		return nil
+	}
+
 	data, err := session.EncodeGob(s.data)
 	if err != nil {
 		return err

+ 14 - 5
vendor/github.com/go-macaron/session/session.go

@@ -27,7 +27,7 @@ import (
 	"gopkg.in/macaron.v1"
 )
 
-const _VERSION = "0.5.0"
+const _VERSION = "0.6.0"
 
 func Version() string {
 	return _VERSION
@@ -95,6 +95,8 @@ type Options struct {
 	IDLength int
 	// Configuration section name. Default is "session".
 	Section string
+	// Ignore release for websocket. Default is false.
+	IgnoreReleaseForWebSocket bool
 }
 
 func prepareOptions(options []Options) Options {
@@ -137,6 +139,9 @@ func prepareOptions(options []Options) Options {
 	if opt.IDLength == 0 {
 		opt.IDLength = sec.Key("ID_LENGTH").MustInt(16)
 	}
+	if !opt.IgnoreReleaseForWebSocket {
+		opt.IgnoreReleaseForWebSocket = sec.Key("IGNORE_RELEASE_FOR_WEBSOCKET").MustBool()
+	}
 
 	return opt
 }
@@ -186,6 +191,10 @@ func Sessioner(options ...Options) macaron.Handler {
 
 		ctx.Next()
 
+		if manager.opt.IgnoreReleaseForWebSocket && ctx.Req.Header.Get("Upgrade") == "websocket" {
+			return
+		}
+
 		if err = sess.Release(); err != nil {
 			panic("session(release): " + err.Error())
 		}
@@ -346,7 +355,7 @@ func (m *Manager) RegenerateId(ctx *macaron.Context) (sess RawStore, err error)
 	if err != nil {
 		return nil, err
 	}
-	ck := &http.Cookie{
+	cookie := &http.Cookie{
 		Name:     m.opt.CookieName,
 		Value:    sid,
 		Path:     m.opt.CookiePath,
@@ -355,10 +364,10 @@ func (m *Manager) RegenerateId(ctx *macaron.Context) (sess RawStore, err error)
 		Domain:   m.opt.Domain,
 	}
 	if m.opt.CookieLifeTime >= 0 {
-		ck.MaxAge = m.opt.CookieLifeTime
+		cookie.MaxAge = m.opt.CookieLifeTime
 	}
-	http.SetCookie(ctx.Resp, ck)
-	ctx.Req.AddCookie(ck)
+	http.SetCookie(ctx.Resp, cookie)
+	ctx.Req.AddCookie(cookie)
 	return sess, nil
 }