Skip to content

Commit

Permalink
Add Secure and CookieHttpOnly parameters (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolphe Houdas authored Aug 17, 2020
1 parent 323cb37 commit d39e15d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ type Options struct {
Section string
// Domain used for `lang` cookie. Default is ""
CookieDomain string
// Set the Secure flag on the `lang` cookie. Default is disabled.
Secure bool
// Set the HTTP Only flag on the `lang` cookie. Default is disabled.
CookieHttpOnly bool
}

func prepareOptions(options []Options) Options {
Expand Down Expand Up @@ -199,7 +203,7 @@ func I18n(options ...Options) macaron.Handler {

// Save language information in cookies.
if !hasCookie {
ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/"+strings.TrimPrefix(opt.SubURL, "/"), opt.CookieDomain)
ctx.SetCookie("lang", curLang.Lang, 1<<31-1, "/"+strings.TrimPrefix(opt.SubURL, "/"), opt.CookieDomain, opt.Secure, opt.CookieHttpOnly)
}

restLangs := make([]LangType, 0, i18n.Count()-1)
Expand Down

0 comments on commit d39e15d

Please sign in to comment.