From 89c880bb27ef061cb6c60cca1ef791aae906c117 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Fri, 8 Nov 2024 13:34:54 -0300 Subject: [PATCH] Fix CORS when OPTIONS method is requested --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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)