Fix session gob (#35128)
Some checks failed
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-docker-rootful (push) Has been cancelled
release-nightly / nightly-docker-rootless (push) Has been cancelled

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,7 +11,6 @@ import (
"code.gitea.io/gitea/modules/log"
session_module "code.gitea.io/gitea/modules/session"
chiSession "gitea.com/go-chi/session"
"github.com/gorilla/sessions"
)
@@ -35,11 +34,11 @@ func (st *SessionsStore) New(r *http.Request, name string) (*sessions.Session, e
// getOrNew gets the session from the chi-session if it exists. Override permits the overriding of an unexpected object.
func (st *SessionsStore) getOrNew(r *http.Request, name string, override bool) (*sessions.Session, error) {
chiStore := chiSession.GetSession(r)
store := session_module.GetContextSession(r)
session := sessions.NewSession(st, name)
rawData := chiStore.Get(name)
rawData := store.Get(name)
if rawData != nil {
oldSession, ok := rawData.(*sessions.Session)
if ok {
@@ -56,21 +55,21 @@ func (st *SessionsStore) getOrNew(r *http.Request, name string, override bool) (
}
session.IsNew = override
session.ID = chiStore.ID() // Simply copy the session id from the chi store
session.ID = store.ID() // Simply copy the session id from the chi store
return session, chiStore.Set(name, session)
return session, store.Set(name, session)
}
// Save should persist session to the underlying store implementation.
func (st *SessionsStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
chiStore := chiSession.GetSession(r)
store := session_module.GetContextSession(r)
if session.IsNew {
_, _ = session_module.RegenerateSession(w, r)
session.IsNew = false
}
if err := chiStore.Set(session.Name(), session); err != nil {
if err := store.Set(session.Name(), session); err != nil {
return err
}
@@ -83,7 +82,7 @@ func (st *SessionsStore) Save(r *http.Request, w http.ResponseWriter, session *s
}
}
return chiStore.Release()
return store.Release()
}
type sizeWriter struct {

View File

@@ -49,7 +49,7 @@ func mockRequest(t *testing.T, reqPath string) *http.Request {
type MockContextOption struct {
Render context.Render
SessionStore *session.MockStore
SessionStore session.Store
}
// MockContext mock context for unit tests