forked from fasthttp/session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
39 lines (32 loc) · 1.12 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fastsession
import (
"github.com/cloudwego/hertz/pkg/app"
"github.com/savsgio/gotils/bytes"
)
// NewDefaultConfig returns a new default configuration
func NewDefaultConfig() Config {
config := Config{
CookieName: defaultSessionKeyName,
Domain: defaultDomain,
Expiration: defaultExpiration,
GCLifetime: defaultGCLifetime,
Secure: defaultSecure,
SessionIDInURLQuery: defaultSessionIDInURLQuery,
SessionNameInURLQuery: defaultSessionKeyName,
SessionIDInHTTPHeader: defaultSessionIDInHTTPHeader,
SessionNameInHTTPHeader: defaultSessionKeyName,
cookieLen: defaultCookieLen,
}
// default sessionIdGeneratorFunc
config.SessionIDGeneratorFunc = config.defaultSessionIDGenerator
// default isSecureFunc
config.IsSecureFunc = config.defaultIsSecureFunc
return config
}
func (c *Config) defaultSessionIDGenerator() []byte {
return bytes.Rand(make([]byte, c.cookieLen))
}
func (c *Config) defaultIsSecureFunc(ctx *app.RequestContext) bool {
//return ctx.IsTLS()
return string(ctx.Request.URI().Scheme()) == "https"
}