Replace bluebell switch path with a query parameter

This commit is contained in:
Melon 2025-03-29 23:47:50 +00:00
parent 870cc23665
commit f3c05c46a8
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -39,7 +39,8 @@ func isInvalidIndexPath(p string) bool {
const ( const (
BetaCookieName = "__bluebell-site-beta" BetaCookieName = "__bluebell-site-beta"
BetaSwitchPath = "/__bluebell-switch-beta" BetaSwitchQuery = "__bluebell-switch-beta"
BetaSwitchResetQuery = "__bluebell-reset-beta"
BetaExpiry = 24 * time.Hour BetaExpiry = 24 * time.Hour
NoCacheQuery = "/?__bluebell-no-cache=" NoCacheQuery = "/?__bluebell-no-cache="
@ -72,8 +73,6 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
host = req.Host host = req.Host
} }
// detect beta switch path
if req.URL.Path == BetaSwitchPath {
q := req.URL.Query() q := req.URL.Query()
// init cookie // init cookie
@ -85,15 +84,17 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
} }
// reset beta // reset beta
if q.Has("reset") { if q.Has(BetaSwitchResetQuery) {
baseCookie.MaxAge = -1 baseCookie.MaxAge = -1
http.SetCookie(rw, baseCookie) http.SetCookie(rw, baseCookie)
cacheBuster(rw, req) cacheBuster(rw, req)
return return
} }
// detect beta switch path
if q.Has(BetaSwitchQuery) {
// set beta branch // set beta branch
baseCookie.Value = q.Get("branch") baseCookie.Value = q.Get(BetaSwitchQuery)
baseCookie.Expires = time.Now().Add(BetaExpiry) baseCookie.Expires = time.Now().Add(BetaExpiry)
http.SetCookie(rw, baseCookie) http.SetCookie(rw, baseCookie)
cacheBuster(rw, req) cacheBuster(rw, req)