mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 13:49:13 -05:00
65ba5b924f
Backport #30375 by @jtran Cookies may exist on "/subpath" and "/subpath/" for some legacy reasons (eg: changed CookiePath behavior in code). The legacy cookie should be removed correctly. Co-authored-by: Jonathan Tran <jonnytran@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Kyle D <kdumontnu@gmail.com> (cherry picked from commit e64926c5193e9ccc30b34f187d96c74d104179ae)
30 lines
790 B
Go
30 lines
790 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package session
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/web/middleware"
|
|
|
|
"gitea.com/go-chi/session"
|
|
)
|
|
|
|
// Store represents a session store
|
|
type Store interface {
|
|
Get(any) any
|
|
Set(any, any) error
|
|
Delete(any) error
|
|
}
|
|
|
|
// RegenerateSession regenerates the underlying session and returns the new store
|
|
func RegenerateSession(resp http.ResponseWriter, req *http.Request) (Store, error) {
|
|
// Ensure that a cookie with a trailing slash does not take precedence over
|
|
// the cookie written by the middleware.
|
|
middleware.DeleteLegacySiteCookie(resp, setting.SessionConfig.CookieName)
|
|
|
|
s, err := session.RegenerateSession(resp, req)
|
|
return s, err
|
|
}
|