mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package session
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hanzoai/git/modules/setting"
|
|
|
|
"github.com/hanzoai/git/modules/session/chi"
|
|
)
|
|
|
|
type RawStore = session.RawStore
|
|
|
|
type Store interface {
|
|
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 := req.Context().Value(MockStoreContextKey); store != nil {
|
|
return store.(Store), nil
|
|
}
|
|
}
|
|
return session.RegenerateSession(resp, req)
|
|
}
|
|
|
|
func GetContextSession(req *http.Request) Store {
|
|
if setting.IsInTesting {
|
|
if store := req.Context().Value(MockStoreContextKey); store != nil {
|
|
return store.(Store)
|
|
}
|
|
}
|
|
return session.GetSession(req)
|
|
}
|
|
|
|
// BeforeRegenerateSession is a list of functions that are called before a session is regenerated.
|
|
var BeforeRegenerateSession []func(http.ResponseWriter, *http.Request)
|