From e92e9f612af48d3629175899adfb35d436144f30 Mon Sep 17 00:00:00 2001 From: fghwett <1058178245@qq.com> Date: Wed, 23 Feb 2022 11:41:32 +0800 Subject: [PATCH] build 5 --- main.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 3c83f1a..852f8e8 100644 --- a/main.go +++ b/main.go @@ -38,28 +38,27 @@ func fetchHandler(w http.ResponseWriter, r *http.Request) { path = strings.TrimPrefix(path, "/") // 获取到的URL path = strings.Replace(path, "https:/", "https://", 1) - u, _ := url.Parse(path) - - match1, _ := regexp.MatchString(exp1, u.String()) - match2, _ := regexp.MatchString(exp2, u.String()) - match3, _ := regexp.MatchString(exp3, u.String()) - match4, _ := regexp.MatchString(exp4, u.String()) - match5, _ := regexp.MatchString(exp5, u.String()) - match6, _ := regexp.MatchString(exp6, u.String()) + match1, _ := regexp.MatchString(exp1, path) + match2, _ := regexp.MatchString(exp2, path) + match3, _ := regexp.MatchString(exp3, path) + match4, _ := regexp.MatchString(exp4, path) + match5, _ := regexp.MatchString(exp5, path) + match6, _ := regexp.MatchString(exp6, path) if match1 || match5 || match6 || match3 || match4 { - httpHandler(w, r, u.String()) + httpHandler(w, r, path) return } else if match2 { - u.Path = strings.ReplaceAll(u.Path, "/blob/", "/raw/") - httpHandler(w, r, u.String()) + path = strings.ReplaceAll(path, "/blob/", "/raw/") + httpHandler(w, r, path) return } - http.Error(w, fmt.Sprintf("%s is not support", u.String()), http.StatusOK) + http.Error(w, fmt.Sprintf("%s is not support", path), http.StatusOK) } 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") != "" { @@ -84,6 +83,7 @@ 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) for k, v := range r.Header {