From 65e154b987f27fbb1ff5d828067335f52a76b894 Mon Sep 17 00:00:00 2001 From: ieb <1@wa.vg> Date: Sat, 21 May 2022 18:33:44 +0800 Subject: [PATCH] some small fix --- login.go | 5 ----- main.go | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/login.go b/login.go index 1b562e8..b7e4c6e 100644 --- a/login.go +++ b/login.go @@ -47,8 +47,3 @@ func handleLogin(w http.ResponseWriter, r *http.Request) { _, _ = io.Copy(w, resp.Body) _ = resp.Body.Close() } - -func serverSideLoginRewriter(resp *http.Response) (err error) { - resp.Header.Add("Set-Cookie", "server_side_login=1; Max-Age=86400; Path=/") - return nil -} diff --git a/main.go b/main.go index 95aea51..64e275e 100644 --- a/main.go +++ b/main.go @@ -70,8 +70,13 @@ func main() { staticRemote, _ := url.Parse("https://f1vp.netlify.app") staticProxy := httputil.NewSingleHostReverseProxy(staticRemote) + serverSideLogin := 0 if login != "" && password != "" { - staticProxy.ModifyResponse = serverSideLoginRewriter + serverSideLogin = 1 + } + staticProxy.ModifyResponse = func(resp *http.Response) (err error) { + resp.Header.Add("Set-Cookie", fmt.Sprintf("server_side_login=%d; Max-Age=86400; Path=/", serverSideLogin)) + return nil } staticHandler := func(w http.ResponseWriter, r *http.Request) { log.Printf("%s FE* - %s\n", r.RemoteAddr, r.URL.String())