From cba26e0c30f27f9590d35b1a05d28a20235372e6 Mon Sep 17 00:00:00 2001 From: NaitLee Date: Wed, 18 Dec 2024 15:47:42 +0800 Subject: [PATCH] fix: cookie logic for chromium (chromium, it's you again) --- main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 7d54b55..c2ca092 100644 --- a/main.go +++ b/main.go @@ -66,16 +66,13 @@ func cmain(argc int, argv []string) string { p1 := r.URL.Path p := strings.Split(p1, "/")[1:] seg := p[0] - vc, err := r.Cookie("view") - if err != nil { - w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly") - w.Header().Add("Location", p1) - w.WriteHeader(http.StatusFound) + if seg == "" { + fileserver.ServeHTTP(w, r) return } - v := vc.Value - if seg != v { - w.Header().Add("Location", "/"+v+p1) + vc, err := r.Cookie("view") + if err == nil && seg != vc.Value { + w.Header().Add("Location", "/"+vc.Value+p1) w.WriteHeader(http.StatusFound) return } @@ -140,8 +137,11 @@ func cmain(argc int, argv []string) string { cmdmap[seg] = conf break } - proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/") - proxy(w, r, proxy_path) + w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly") + w.Header().Add("Location", p1) + w.WriteHeader(http.StatusFound) + // proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/") + // proxy(w, r, proxy_path) return } fileserver.ServeHTTP(w, r)