Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for incorrect and missing schemes. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Version = "0.2.1"
var options struct {
origin string
printVersion bool
insecure bool
insecure bool
}

func main() {
Expand Down Expand Up @@ -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
Expand Down