From ce2159abc7db60e12de5982847bfda25c412f96c Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Wed, 23 Feb 2022 11:55:56 +0800 Subject: [PATCH] build 7 --- main.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 7f0d589..5b2ff10 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "net/http" - "net/url" "regexp" "strings" ) @@ -84,14 +83,10 @@ func httpHandler(w http.ResponseWriter, r *http.Request, pathname string) { func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname string) { fmt.Println("Proxy: ", pathname) - r.URL, _ = url.Parse(pathname) - req, _ := http.NewRequest(r.Method, r.URL.String(), r.Body) + req, _ := http.NewRequest(r.Method, pathname, r.Body) for k, v := range r.Header { req.Header.Set(k, v[0]) } - for _, value := range r.Cookies() { - w.Header().Add(value.Name, value.Value) - } res, e := client.Do(req) if e != nil { fmt.Println("Proxy Error: ", pathname, e) @@ -105,7 +100,8 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname res.Header.Set("location", PREFIX+location) } else { newReq, _ := http.NewRequest(r.Method, location, res.Body) - proxy(w, newReq, http.DefaultClient, location) + client.CheckRedirect = nil + proxy(w, newReq, client, location) return } } @@ -117,11 +113,12 @@ func proxy(w http.ResponseWriter, r *http.Request, client *http.Client, pathname res.Header.Del("Content-Security-Policy-Report-Only") res.Header.Del("Clear-Site-Data") - w.WriteHeader(res.StatusCode) for k, v := range res.Header { w.Header().Set(k, strings.Join(v, ",")) } _ = res.Write(w) + w.WriteHeader(res.StatusCode) + fmt.Println("result: ", res.StatusCode) } func main() {