Fix CORS when OPTIONS method is requested
All checks were successful
CI / build (push) Successful in 5m43s

This commit is contained in:
Fijxu 2024-11-08 13:34:54 -03:00
parent 40436dcf92
commit 89c880bb27
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -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)