Added MaxLength support port of: https://github.com/boj/redistore/pull/5
This commit is contained in:
19
pgstore.go
19
pgstore.go
@@ -3,13 +3,14 @@ package pgstore
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/base32"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coopernurse/gorp"
|
||||
"github.com/gorilla/securecookie"
|
||||
"github.com/gorilla/sessions"
|
||||
_ "github.com/lib/pq"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type PGStore struct {
|
||||
@@ -123,6 +124,18 @@ func (db *PGStore) Save(r *http.Request, w http.ResponseWriter, session *session
|
||||
return nil
|
||||
}
|
||||
|
||||
// MaxLength restricts the maximum length of new sessions to l.
|
||||
// If l is 0 there is no limit to the size of a session, use with caution.
|
||||
// The default for a new PGStore is 4096. PostgreSQL allows for max
|
||||
// value sizes of up to 1GB (http://www.postgresql.org/docs/current/interactive/datatype-character.html)
|
||||
func (s *PGStore) MaxLength(l int) {
|
||||
for _, c := range s.Codecs {
|
||||
if codec, ok := c.(*securecookie.SecureCookie); ok {
|
||||
codec.MaxLength(l)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//load fetches a session by ID from the database and decodes its content into session.Values
|
||||
func (db *PGStore) load(session *sessions.Session) error {
|
||||
var s Session
|
||||
|
Reference in New Issue
Block a user