mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-14 05:11:17 +08:00
chore: add a new cors response header
This commit is contained in:
parent
fb1c0aa387
commit
2e87c6f4da
@ -63,6 +63,7 @@ func Start(addr string, tlsAddr string, secret string,
|
||||
AllowedHeaders: []string{"Content-Type", "Authorization"},
|
||||
MaxAge: 300,
|
||||
})
|
||||
r.Use(setPrivateNetworkAccess)
|
||||
r.Use(corsM.Handler)
|
||||
if isDebug {
|
||||
r.Mount("/debug", func() http.Handler {
|
||||
@ -149,6 +150,15 @@ func Start(addr string, tlsAddr string, secret string,
|
||||
|
||||
}
|
||||
|
||||
func setPrivateNetworkAccess(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodOptions && r.Header.Get("Access-Control-Request-Method") != "" {
|
||||
w.Header().Add("Access-Control-Allow-Private-Network", "true")
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func safeEuqal(a, b string) bool {
|
||||
aBuf := utils.ImmutableBytesFromString(a)
|
||||
bBuf := utils.ImmutableBytesFromString(b)
|
||||
|
Loading…
Reference in New Issue
Block a user