diff --git a/normalize.go b/normalize.go index a774f74..168da12 100644 --- a/normalize.go +++ b/normalize.go @@ -5,7 +5,8 @@ import ( "strings" ) -// NormalizeURL normalizes the url and replaces http://, https:// schemes by ws://, wss://. +// NormalizeURL normalizes the url and replaces http://, https:// schemes with ws://, wss:// +// and normalizes the path. func NormalizeURL(u string) string { if u == "" { return "" @@ -32,3 +33,12 @@ func NormalizeURL(u string) string { return p.String() } + +// NormalizeOKMessage takes a string message that is to be sent in an `OK` or `CLOSED` command +// and prefixes it with ": " if it doesn't already have an acceptable prefix. +func NormalizeOKMessage(reason string, prefix string) string { + if idx := strings.Index(reason, ": "); idx == -1 || strings.IndexByte(reason[0:idx], ' ') != -1 { + return prefix + ": " + reason + } + return reason +}