fix: cookie logic for chromium (chromium, it's you again)

This commit is contained in:
Konuri Maki 2024-12-18 15:47:42 +08:00
parent 24bae2ac48
commit cba26e0c30

20
main.go
View file

@ -66,16 +66,13 @@ func cmain(argc int, argv []string) string {
p1 := r.URL.Path p1 := r.URL.Path
p := strings.Split(p1, "/")[1:] p := strings.Split(p1, "/")[1:]
seg := p[0] seg := p[0]
vc, err := r.Cookie("view") if seg == "" {
if err != nil { fileserver.ServeHTTP(w, r)
w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly")
w.Header().Add("Location", p1)
w.WriteHeader(http.StatusFound)
return return
} }
v := vc.Value vc, err := r.Cookie("view")
if seg != v { if err == nil && seg != vc.Value {
w.Header().Add("Location", "/"+v+p1) w.Header().Add("Location", "/"+vc.Value+p1)
w.WriteHeader(http.StatusFound) w.WriteHeader(http.StatusFound)
return return
} }
@ -140,8 +137,11 @@ func cmain(argc int, argv []string) string {
cmdmap[seg] = conf cmdmap[seg] = conf
break break
} }
proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/") w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly")
proxy(w, r, proxy_path) w.Header().Add("Location", p1)
w.WriteHeader(http.StatusFound)
// proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/")
// proxy(w, r, proxy_path)
return return
} }
fileserver.ServeHTTP(w, r) fileserver.ServeHTTP(w, r)