diff --git a/url/parsers.go b/url/parsers.go index 891f988..fa575e7 100644 --- a/url/parsers.go +++ b/url/parsers.go @@ -138,7 +138,15 @@ func absoluteURLParser(u *URL) (*URL, error) { return u, nil } // Try to parse host related input - if stringsutil.HasPrefixAny(u.Original, HTTP+SchemeSeparator, HTTPS+SchemeSeparator, "//") { + allowedSchemes := []string{ + HTTP + SchemeSeparator, + HTTPS + SchemeSeparator, + WEBSOCKET + SchemeSeparator, + WEBSOCKET_SSL + SchemeSeparator, + FTP + SchemeSeparator, + "//", + } + if stringsutil.HasPrefixAny(u.Original, allowedSchemes...) { u.IsRelative = false urlparse, parseErr := url.Parse(u.Original) if parseErr != nil { diff --git a/url/url_test.go b/url/url_test.go index 925840e..8c001f9 100644 --- a/url/url_test.go +++ b/url/url_test.go @@ -53,6 +53,13 @@ func TestParse(t *testing.T) { require.Equal(t, "127.0.0.1", U.Hostname(), "different host") require.Equal(t, "a", U.Fragment, "different fragment") require.Equal(t, "http://127.0.0.1/#a", U.String(), "different full url") + + // websocket + U, err = Parse("wss://127.0.0.1") + require.Nil(t, err, "could not parse url") + require.Equal(t, "wss", U.Scheme, "different scheme") + require.Equal(t, "127.0.0.1", U.Hostname(), "different host") + require.Equal(t, "wss://127.0.0.1", U.String(), "different full url") } func TestClone(t *testing.T) { diff --git a/url/utils.go b/url/utils.go index 6970b29..0ebc023 100644 --- a/url/utils.go +++ b/url/utils.go @@ -8,8 +8,16 @@ import ( ) const ( - HTTP = "http" - HTTPS = "https" + HTTP = "http" + HTTPS = "https" + + // Deny all protocols + // Allow: + // websocket + websocket over ssl + WEBSOCKET = "ws" + WEBSOCKET_SSL = "wss" + FTP = "ftp" + SchemeSeparator = "://" DefaultHTTPPort = "80" DefaultHTTPSPort = "443"