diff --git a/sessions.go b/sessions.go index fe0d2bc..cde3c0a 100644 --- a/sessions.go +++ b/sessions.go @@ -22,14 +22,15 @@ const flashesKey = "_flash" // // Fields are a subset of http.Cookie fields. type Options struct { - Path string - Domain string + Path string + Domain string // MaxAge=0 means no 'Max-Age' attribute specified. // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'. // MaxAge>0 means Max-Age attribute present and given in seconds. - MaxAge int - Secure bool - HttpOnly bool + MaxAge int + MaxLength int + Secure bool + HttpOnly bool } // Session -------------------------------------------------------------------- diff --git a/store.go b/store.go index 4ff6b6c..b1cf3c2 100644 --- a/store.go +++ b/store.go @@ -127,6 +127,19 @@ func (s *CookieStore) MaxAge(age int) { } } +// MaxLength sets the maximum length for the store and the underlying cookie +// implementation. +func (s *CookieStore) MaxLength(length int) { + s.Options.MaxLength = length + + // Set the maxAge for each securecookie instance. + for _, codec := range s.Codecs { + if sc, ok := codec.(*securecookie.SecureCookie); ok { + sc.MaxLength(length) + } + } +} + // FilesystemStore ------------------------------------------------------------ var fileMutex sync.RWMutex