diff --git a/connection.go b/connection.go index 9a6265e..55fa90b 100644 --- a/connection.go +++ b/connection.go @@ -24,7 +24,7 @@ func connect(url, origin string, rlConf *readline.Config, allowInsecure bool) er dialer := websocket.Dialer{ Proxy: http.ProxyFromEnvironment, - TLSClientConfig:&tls.Config{ + TLSClientConfig: &tls.Config{ InsecureSkipVerify: allowInsecure, }, } diff --git a/main.go b/main.go index 7fdc26b..8847ad1 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ const Version = "0.2.1" var options struct { origin string printVersion bool - insecure bool + insecure bool } func main() { @@ -50,6 +50,22 @@ func root(cmd *cobra.Command, args []string) { os.Exit(1) } + // Correct and add missing schemes. + switch dest.Scheme { + case "ws", "wss": + case "http": + dest.Scheme = "ws" + case "https": + dest.Scheme = "wss" + default: + // Likely no scheme at all, e.g. "localhost:8000". + dest, err = url.Parse("ws://" + args[0]) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + } + var origin string if options.origin != "" { origin = options.origin