1
1
mirror of https://github.com/go-gitea/gitea synced 2025-09-28 03:28:13 +00:00

Fix session gob (#35128)

Fix #35126
This commit is contained in:
wxiaoguang
2025-07-20 09:49:36 +08:00
committed by GitHub
parent 3531e9dbfd
commit 86aafea3fb
12 changed files with 131 additions and 72 deletions

View File

@@ -11,25 +11,25 @@ import (
"gitea.com/go-chi/session"
)
// Store represents a session store
type RawStore = session.RawStore
type Store interface {
Get(any) any
Set(any, any) error
Delete(any) error
ID() string
Release() error
Flush() error
RawStore
Destroy(http.ResponseWriter, *http.Request) error
}
type mockStoreContextKeyStruct struct{}
var MockStoreContextKey = mockStoreContextKeyStruct{}
// RegenerateSession regenerates the underlying session and returns the new store
func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error) {
for _, f := range BeforeRegenerateSession {
f(resp, req)
}
if setting.IsInTesting {
if store, ok := req.Context().Value(MockStoreContextKey).(*MockStore); ok {
return store, nil
if store := req.Context().Value(MockStoreContextKey); store != nil {
return store.(Store), nil
}
}
return session.RegenerateSession(resp, req)
@@ -37,8 +37,8 @@ func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, erro
func GetContextSession(req *http.Request) Store {
if setting.IsInTesting {
if store, ok := req.Context().Value(MockStoreContextKey).(*MockStore); ok {
return store
if store := req.Context().Value(MockStoreContextKey); store != nil {
return store.(Store)
}
}
return session.GetSession(req)