diff --git a/Gopkg.lock b/Gopkg.lock index 176470d0..5900c466 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -119,7 +119,7 @@ branch = "master" name = "github.com/json-iterator/go" packages = ["."] - revision = "2dc0031b26575ddf5dab09ab7795105a05575473" + revision = "13f86432b882000a51c6e610c620974462691a97" [[projects]] branch = "master" diff --git a/_examples/README.md b/_examples/README.md old mode 100755 new mode 100644 diff --git a/configuration.go b/configuration.go index a171ae3e..885555f2 100644 --- a/configuration.go +++ b/configuration.go @@ -32,7 +32,7 @@ func init() { filename := homeConfigurationFilename(".yml") c, err := parseYAML(filename) if err != nil { - // this error will be occured the first time that the configuration + // this error will be occurred the first time that the configuration // file doesn't exist. // Create the YAML-ONLY global configuration file now using the default configuration 'c'. // This is useful when we run multiple iris servers that share the same diff --git a/context/context.go b/context/context.go index a669f619..e3a38ad8 100644 --- a/context/context.go +++ b/context/context.go @@ -2523,7 +2523,7 @@ func (ctx *context) RemoveCookie(name string) { c.Expires = exp c.MaxAge = -1 ctx.SetCookie(c) - // delete request's cookie also, which is temporary available + // delete request's cookie also, which is temporary available. ctx.request.Header.Set("Cookie", "") } diff --git a/middleware/README.md b/middleware/README.md old mode 100755 new mode 100644 diff --git a/sessions/config.go b/sessions/config.go index 4cafddfe..37d94ca9 100644 --- a/sessions/config.go +++ b/sessions/config.go @@ -56,6 +56,13 @@ type ( // Defaults to false. CookieSecureTLS bool + // AllowReclaim will allow to + // Destroy and Start a session in the same request handler. + // All it does is that it removes the cookie for both `Request` and `ResponseWriter`. + // + // Defaults to false. + AllowReclaim bool + // Encode the cookie value if not nil. // Should accept as first argument the cookie name (config.Cookie) // as second argument the server's generated session id. diff --git a/sessions/cookie.go b/sessions/cookie.go index b1942729..b4698b39 100644 --- a/sessions/cookie.go +++ b/sessions/cookie.go @@ -38,7 +38,8 @@ func AddCookie(ctx context.Context, cookie *http.Cookie) { } // RemoveCookie deletes a cookie by it's name/key -func RemoveCookie(ctx context.Context, name string) { +// If "purge" is true then it removes the, temp, cookie from the request as well. +func RemoveCookie(ctx context.Context, name string, purge bool) { c, err := ctx.Request().Cookie(name) if err != nil { return @@ -50,6 +51,11 @@ func RemoveCookie(ctx context.Context, name string) { c.Value = "" c.Path = "/" AddCookie(ctx, c) + + if purge { + // delete request's cookie also, which is temporary available. + ctx.Request().Header.Set("Cookie", "") + } } // IsValidCookieDomain returns true if the receiver is a valid domain to set diff --git a/sessions/sessions.go b/sessions/sessions.go index 7df70e20..3a45e26a 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -146,7 +146,7 @@ func (s *Sessions) Destroy(ctx context.Context) { if cookieValue == "" { // nothing to destroy return } - RemoveCookie(ctx, s.config.Cookie) + RemoveCookie(ctx, s.config.Cookie, s.config.AllowReclaim) s.provider.Destroy(cookieValue) }