build 5
This commit is contained in:
24
main.go
24
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 {
|
||||
|
||||
Reference in New Issue
Block a user