Permalink
Browse files

Allow changing the prefix for cookies

  • Loading branch information...
1 parent b84f304 commit 0732377b1f475c50a56cbc4c79cd344048713c5f @robfig committed Oct 14, 2012
Showing with 15 additions and 6 deletions.
  1. +14 −6 mvc.go
  2. +1 −0 skeleton/conf/app.conf.template
View
20 mvc.go
@@ -240,7 +240,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
flashValue += "\x00" + key + ":" + value + "\x00"
}
c.SetCookie(&http.Cookie{
- Name: "REVEL_FLASH",
+ Name: COOKIE_PREFIX + "_FLASH",
Value: url.QueryEscape(flashValue),
Path: "/",
})
@@ -255,7 +255,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
}
}
c.SetCookie(&http.Cookie{
- Name: "REVEL_ERRORS",
+ Name: COOKIE_PREFIX + "_ERRORS",
Value: url.QueryEscape(errorsValue),
Path: "/",
})
@@ -267,7 +267,7 @@ func (c *Controller) Invoke(appControllerPtr reflect.Value, method reflect.Value
}
sessionData := url.QueryEscape(sessionValue)
c.SetCookie(&http.Cookie{
- Name: "REVEL_SESSION",
+ Name: COOKIE_PREFIX + "_SESSION",
Value: Sign(sessionData) + "-" + sessionData,
Path: "/",
})
@@ -502,7 +502,7 @@ func restoreFlash(req *http.Request) Flash {
Data: make(map[string]string),
Out: make(map[string]string),
}
- if cookie, err := req.Cookie("REVEL_FLASH"); err == nil {
+ if cookie, err := req.Cookie(COOKIE_PREFIX + "_FLASH"); err == nil {
ParseKeyValueCookie(cookie.Value, func(key, val string) {
flash.Data[key] = val
})
@@ -513,7 +513,7 @@ func restoreFlash(req *http.Request) Flash {
// Restore Validation.Errors from a request.
func restoreValidationErrors(req *http.Request) []*ValidationError {
errors := make([]*ValidationError, 0, 5)
- if cookie, err := req.Cookie("REVEL_ERRORS"); err == nil {
+ if cookie, err := req.Cookie(COOKIE_PREFIX + "_ERRORS"); err == nil {
ParseKeyValueCookie(cookie.Value, func(key, val string) {
errors = append(errors, &ValidationError{
Key: key,
@@ -526,7 +526,7 @@ func restoreValidationErrors(req *http.Request) []*ValidationError {
func restoreSession(req *http.Request) Session {
session := make(map[string]string)
- cookie, err := req.Cookie("REVEL_SESSION")
+ cookie, err := req.Cookie(COOKIE_PREFIX + "_SESSION")
if err != nil {
return Session(session)
}
@@ -656,6 +656,14 @@ func (resp *Response) WriteHeader(defaultStatusCode int, defaultContentType stri
resp.Out.WriteHeader(resp.Status)
}
+var COOKIE_PREFIX string
+
+func init() {
+ InitHooks = append(InitHooks, func() {
+ COOKIE_PREFIX = Config.StringDefault("session.cookie", "REVEL")
+ })
+}
+
// Internal bookeeping
type ControllerType struct {
View
1 skeleton/conf/app.conf.template
@@ -2,6 +2,7 @@ app.name={{ .AppName }}
app.secret={{ .Secret }}
http.addr=
http.port=9000
+session.cookie=REVEL
[dev]
results.pretty=true

0 comments on commit 0732377

Please sign in to comment.