优化结构
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user