From 0d5b801c78f55287cb06585391fd27e3c700b49d Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Wed, 23 Feb 2022 19:42:35 +0800 Subject: [PATCH] build 9 --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 0a589f2..d77fa85 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func httpHandler(w http.ResponseWriter, r *http.Request, pathname string) { fmt.Println("Handle: ", pathname) reqHdrRaw := r.Header - if r.Method == http.MethodOptions && reqHdrRaw.Get("access-control-request-headers") != "" { + if r.Method == http.MethodOptions && reqHdrRaw.Get("Access-Control-Request-Headers") != "" { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, TRACE, DELETE, HEAD, OPTIONS") w.Header().Set("Access-Control-Max-Age", "1728000") @@ -85,7 +85,7 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname fmt.Println("Proxy: ", pathname) req, _ := http.NewRequest(r.Method, pathname, r.Body) for k, v := range r.Header { - req.Header.Set(k, v[0]) + req.Header.Set(k, strings.Join(v, ",")) } res, e := client.Do(req) if e != nil { @@ -94,10 +94,12 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname return } - if res.Header.Get("location") != "" { - location := res.Header.Get("location") + if res.Header.Get("Location") != "" { + location := res.Header.Get("Location") + fmt.Println("Location: ", location) + if checkUrl(location) { - res.Header.Set("location", PREFIX+location) + res.Header.Set("Location", PREFIX+location) } else { newReq, _ := http.NewRequest(r.Method, location, res.Body) client.CheckRedirect = nil