@@ -106,19 +106,31 @@ func prepareSession(env Env, key, secret string) {
106
106
env ["mango.session" ] = make (map [string ]interface {})
107
107
}
108
108
109
- func commitSession (headers Headers , env Env , key , secret , domain string ) {
109
+ func commitSession (headers Headers , env Env , key , secret string , options * CookieOptions ) {
110
110
cookie := new (http.Cookie )
111
111
cookie .Name = key
112
112
cookie .Value = encodeCookie (env ["mango.session" ].(map [string ]interface {}), secret )
113
- cookie .Domain = domain
113
+ cookie .Path = options .Path
114
+ cookie .Domain = options .Domain
115
+ cookie .MaxAge = options .MaxAge
116
+ cookie .Secure = options .Secure
117
+ cookie .HttpOnly = options .HttpOnly
114
118
headers .Add ("Set-Cookie" , cookie .String ())
115
119
}
116
120
117
- func Sessions (secret , key , domain string ) Middleware {
121
+ type CookieOptions struct {
122
+ Domain string
123
+ Path string
124
+ MaxAge int
125
+ Secure bool
126
+ HttpOnly bool
127
+ }
128
+
129
+ func Sessions (secret , key string , options * CookieOptions ) Middleware {
118
130
return func (env Env , app App ) (status Status , headers Headers , body Body ) {
119
131
prepareSession (env , key , secret )
120
132
status , headers , body = app (env )
121
- commitSession (headers , env , key , secret , domain )
133
+ commitSession (headers , env , key , secret , options )
122
134
return status , headers , body
123
135
}
124
136
}
0 commit comments