1
0
Fork 0
forked from forgejo/forgejo

Update github.com/lafriks/xormstore and tidy up mod.go (#8020)

This commit is contained in:
guillep2k 2019-08-28 18:17:14 -03:00 committed by Antoine GIRARD
parent dd3ba9bb6b
commit cedb285e25
20 changed files with 286 additions and 165 deletions

View file

@ -5,34 +5,16 @@
package sessions
import (
"context"
"encoding/gob"
"fmt"
"net/http"
"time"
"github.com/gorilla/context"
)
// Default flashes key.
const flashesKey = "_flash"
// Options --------------------------------------------------------------------
// Options stores configuration for a session or session store.
//
// Fields are a subset of http.Cookie fields.
type Options struct {
Path string
Domain string
// MaxAge=0 means no Max-Age attribute specified and the cookie will be
// deleted after the browser session ends.
// MaxAge<0 means delete cookie immediately.
// MaxAge>0 means Max-Age attribute present and given in seconds.
MaxAge int
Secure bool
HttpOnly bool
}
// Session --------------------------------------------------------------------
// NewSession is called by session stores to create a new session instance.
@ -125,7 +107,8 @@ const registryKey contextKey = 0
// GetRegistry returns a registry instance for the current request.
func GetRegistry(r *http.Request) *Registry {
registry := context.Get(r, registryKey)
var ctx = r.Context()
registry := ctx.Value(registryKey)
if registry != nil {
return registry.(*Registry)
}
@ -133,7 +116,7 @@ func GetRegistry(r *http.Request) *Registry {
request: r,
sessions: make(map[string]sessionInfo),
}
context.Set(r, registryKey, newRegistry)
*r = *r.WithContext(context.WithValue(ctx, registryKey, newRegistry))
return newRegistry
}
@ -195,15 +178,7 @@ func Save(r *http.Request, w http.ResponseWriter) error {
// the Expires field calculated based on the MaxAge value, for Internet
// Explorer compatibility.
func NewCookie(name, value string, options *Options) *http.Cookie {
cookie := &http.Cookie{
Name: name,
Value: value,
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,
}
cookie := newCookieFromOptions(name, value, options)
if options.MaxAge > 0 {
d := time.Duration(options.MaxAge) * time.Second
cookie.Expires = time.Now().Add(d)