mirror of
https://github.com/1f349/site-hosting.git
synced 2025-04-13 23:26:02 +01:00
Replace bluebell switch path with a query parameter
This commit is contained in:
parent
870cc23665
commit
f3c05c46a8
@ -38,9 +38,10 @@ func isInvalidIndexPath(p string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BetaCookieName = "__bluebell-site-beta"
|
BetaCookieName = "__bluebell-site-beta"
|
||||||
BetaSwitchPath = "/__bluebell-switch-beta"
|
BetaSwitchQuery = "__bluebell-switch-beta"
|
||||||
BetaExpiry = 24 * time.Hour
|
BetaSwitchResetQuery = "__bluebell-reset-beta"
|
||||||
|
BetaExpiry = 24 * time.Hour
|
||||||
|
|
||||||
NoCacheQuery = "/?__bluebell-no-cache="
|
NoCacheQuery = "/?__bluebell-no-cache="
|
||||||
)
|
)
|
||||||
@ -72,28 +73,28 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
host = req.Host
|
host = req.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q := req.URL.Query()
|
||||||
|
|
||||||
|
// init cookie
|
||||||
|
baseCookie := &http.Cookie{
|
||||||
|
Name: BetaCookieName,
|
||||||
|
Path: "/",
|
||||||
|
HttpOnly: true,
|
||||||
|
SameSite: http.SameSiteLaxMode,
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset beta
|
||||||
|
if q.Has(BetaSwitchResetQuery) {
|
||||||
|
baseCookie.MaxAge = -1
|
||||||
|
http.SetCookie(rw, baseCookie)
|
||||||
|
cacheBuster(rw, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// detect beta switch path
|
// detect beta switch path
|
||||||
if req.URL.Path == BetaSwitchPath {
|
if q.Has(BetaSwitchQuery) {
|
||||||
q := req.URL.Query()
|
|
||||||
|
|
||||||
// init cookie
|
|
||||||
baseCookie := &http.Cookie{
|
|
||||||
Name: BetaCookieName,
|
|
||||||
Path: "/",
|
|
||||||
HttpOnly: true,
|
|
||||||
SameSite: http.SameSiteLaxMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset beta
|
|
||||||
if q.Has("reset") {
|
|
||||||
baseCookie.MaxAge = -1
|
|
||||||
http.SetCookie(rw, baseCookie)
|
|
||||||
cacheBuster(rw, req)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user