fix: fix cookie redirect logic again

This commit is contained in:
NaitLee 2024-12-18 15:57:53 +08:00
parent cba26e0c30
commit 72c2044a8d

View file

@ -67,16 +67,21 @@ func cmain(argc int, argv []string) string {
p := strings.Split(p1, "/")[1:]
seg := p[0]
if seg == "" {
w.Header().Add("Set-Cookie", "view=; Path=/; SameSite=Strict; HttpOnly")
w.Header().Add("Cache-Control", "no-store")
fileserver.ServeHTTP(w, r)
return
}
vc, err := r.Cookie("view")
if err == nil && seg != vc.Value {
if err == nil && seg != vc.Value && vc.Value != "" {
w.Header().Add("Location", "/"+vc.Value+p1)
w.WriteHeader(http.StatusFound)
return
}
if conf, ok := cmdmap[seg]; ok {
if err != nil || vc.Value == "" {
w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly")
}
proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/")
proxy(w, r, proxy_path)
return