Fix CORS when OPTIONS method is requested
All checks were successful
CI / build (push) Successful in 5m43s
All checks were successful
CI / build (push) Successful in 5m43s
This commit is contained in:
parent
40436dcf92
commit
89c880bb27
1 changed files with 4 additions and 4 deletions
8
main.go
8
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)
|
||||
|
|
Loading…
Reference in a new issue