Skip to content

Commit

Permalink
feat: set http_only flag for cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 10, 2024
1 parent 939e956 commit 631af1f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,18 @@ func main() {
//server.Use(gzip.Gzip(gzip.DefaultCompression)) // conflict with sse

// Initialize session store
var store sessions.Store
if common.RedisEnabled {
opt := common.ParseRedisOption()
store, _ := redis.NewStore(opt.MinIdleConns, opt.Network, opt.Addr, opt.Password, []byte(common.SessionSecret))
server.Use(sessions.Sessions("session", store))
store, _ = redis.NewStore(opt.MinIdleConns, opt.Network, opt.Addr, opt.Password, []byte(common.SessionSecret))
} else {
store := cookie.NewStore([]byte(common.SessionSecret))
server.Use(sessions.Sessions("session", store))
store = cookie.NewStore([]byte(common.SessionSecret))
}
store.Options(sessions.Options{
HttpOnly: true,
MaxAge: 30 * 24 * 3600,
})
server.Use(sessions.Sessions("session", store))

router.SetRouter(server, buildFS, indexPage)
var port = os.Getenv("PORT")
Expand Down

0 comments on commit 631af1f

Please sign in to comment.