fix localhost trick from 8aaf5b.
This commit is contained in:
@@ -15,13 +15,12 @@ func NormalizeURL(u string) string {
|
|||||||
u = strings.TrimSpace(u)
|
u = strings.TrimSpace(u)
|
||||||
u = strings.ToLower(u)
|
u = strings.ToLower(u)
|
||||||
|
|
||||||
if strings.HasPrefix(u, "localhost") == true {
|
if strings.Split(u, ":")[0] == "localhost" {
|
||||||
u = "ws://" + u
|
u = "ws://" + u
|
||||||
}
|
} else if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
|
||||||
|
|
||||||
if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
|
|
||||||
u = "wss://" + u
|
u = "wss://" + u
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := url.Parse(u)
|
p, err := url.Parse(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ var urlTests = []urlTest{
|
|||||||
{"x.com/?x=23", "wss://x.com?x=23"},
|
{"x.com/?x=23", "wss://x.com?x=23"},
|
||||||
{"localhost:4036", "ws://localhost:4036"},
|
{"localhost:4036", "ws://localhost:4036"},
|
||||||
{"localhost:4036/relay", "ws://localhost:4036/relay"},
|
{"localhost:4036/relay", "ws://localhost:4036/relay"},
|
||||||
|
{"localhostmagnanimus.com", "wss://localhostmagnanimus.com"},
|
||||||
{NormalizeURL("localhost:4036/relay"), "ws://localhost:4036/relay"},
|
{NormalizeURL("localhost:4036/relay"), "ws://localhost:4036/relay"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNormalizeURL(t *testing.T) {
|
func TestNormalizeURL(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range urlTests {
|
for _, test := range urlTests {
|
||||||
if output := NormalizeURL(test.url); output != test.expected {
|
if output := NormalizeURL(test.url); output != test.expected {
|
||||||
t.Errorf("Output '%s' not equal to expected '%s'", output, test.expected)
|
t.Errorf("Output '%s' not equal to expected '%s'", output, test.expected)
|
||||||
|
|||||||
Reference in New Issue
Block a user