3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

use consistent spelling of WebSocket

This commit is contained in:
Shivaram Lingamneni 2020-05-05 04:07:19 -04:00
parent 3d3aec6979
commit 620e30293d
2 changed files with 5 additions and 5 deletions

View File

@ -478,7 +478,7 @@ type Config struct {
Listeners map[string]listenerConfigBlock Listeners map[string]listenerConfigBlock
UnixBindMode os.FileMode `yaml:"unix-bind-mode"` UnixBindMode os.FileMode `yaml:"unix-bind-mode"`
TorListeners TorListenersConfig `yaml:"tor-listeners"` TorListeners TorListenersConfig `yaml:"tor-listeners"`
Websockets struct { WebSockets struct {
AllowedOrigins []string `yaml:"allowed-origins"` AllowedOrigins []string `yaml:"allowed-origins"`
allowedOriginRegexps []*regexp.Regexp allowedOriginRegexps []*regexp.Regexp
} }
@ -844,12 +844,12 @@ func LoadConfig(filename string) (config *Config, err error) {
return nil, fmt.Errorf("failed to prepare listeners: %v", err) return nil, fmt.Errorf("failed to prepare listeners: %v", err)
} }
for _, glob := range config.Server.Websockets.AllowedOrigins { for _, glob := range config.Server.WebSockets.AllowedOrigins {
globre, err := utils.CompileGlob(glob) globre, err := utils.CompileGlob(glob)
if err != nil { if err != nil {
return nil, fmt.Errorf("invalid websocket allowed-origin expression: %s", glob) return nil, fmt.Errorf("invalid websocket allowed-origin expression: %s", glob)
} }
config.Server.Websockets.allowedOriginRegexps = append(config.Server.Websockets.allowedOriginRegexps, globre) config.Server.WebSockets.allowedOriginRegexps = append(config.Server.WebSockets.allowedOriginRegexps, globre)
} }
if config.Server.STS.Enabled { if config.Server.STS.Enabled {

View File

@ -164,14 +164,14 @@ func (wl *WSListener) handle(w http.ResponseWriter, r *http.Request) {
wsUpgrader := websocket.Upgrader{ wsUpgrader := websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { CheckOrigin: func(r *http.Request) bool {
if len(config.Server.Websockets.allowedOriginRegexps) == 0 { if len(config.Server.WebSockets.allowedOriginRegexps) == 0 {
return true return true
} }
origin := strings.TrimSpace(r.Header.Get("Origin")) origin := strings.TrimSpace(r.Header.Get("Origin"))
if len(origin) == 0 { if len(origin) == 0 {
return false return false
} }
for _, re := range config.Server.Websockets.allowedOriginRegexps { for _, re := range config.Server.WebSockets.allowedOriginRegexps {
if re.MatchString(origin) { if re.MatchString(origin) {
return true return true
} }