优化结构

This commit is contained in:
Yvan
2026-08-28 18:22:16 +08:00
parent 8d290f2954
commit ac09f38940
6 changed files with 224 additions and 10 deletions
+3 -7
View File
@@ -3,7 +3,6 @@ package websocket
import (
"net/http"
"net/url"
"strings"
"sync"
"time"
@@ -80,12 +79,9 @@ func New(config Config) *Server {
allowed := append([]string(nil), c.AllowOrigins...)
m.Upgrader.CheckOrigin = func(r *http.Request) bool {
if len(allowed) == 0 {
origin := r.Header.Get("Origin")
if origin == "" {
return true
}
parsed, err := url.Parse(origin)
return err == nil && strings.EqualFold(parsed.Host, r.Host)
// An empty allowlist means no origin restriction. Deployments that
// need a restriction can provide allow_origins explicitly.
return true
}
origin := r.Header.Get("Origin")
for _, value := range allowed {