diff --git a/main.go b/main.go index 65be33c..cee7c20 100644 --- a/main.go +++ b/main.go @@ -321,6 +321,10 @@ func beforeProxy(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { defer panicHandler(w) + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Headers", "*") + w.Header().Set("Access-Control-Max-Age", "1728000") + // To prevent accessing from the bare IP address if req.Host == "" || net.ParseIP(strings.Split(req.Host, ":")[0]) != nil { w.WriteHeader(444) @@ -345,10 +349,6 @@ func beforeProxy(next http.HandlerFunc) http.HandlerFunc { req.Header.Add("Origin", "https://www.youtube.com") req.Header.Add("Referer", "https://www.youtube.com/") - w.Header().Set("Access-Control-Allow-Origin", "*") - w.Header().Set("Access-Control-Allow-Headers", "*") - w.Header().Set("Access-Control-Max-Age", "1728000") - atomic.AddInt64(&stats_.RequestCount, 1) metrics.RequestCount.Inc() next(w, req)