|
|
@@ -64,6 +64,20 @@ func Dial(url_, protocol, origin string) (ws *Conn, err error) {
|
|
|
return DialConfig(config)
|
|
|
}
|
|
|
|
|
|
+var portMap = map[string]string{
|
|
|
+ "ws": "80",
|
|
|
+ "wss": "443",
|
|
|
+}
|
|
|
+
|
|
|
+func parseAuthority(location *url.URL) string {
|
|
|
+ if _, ok := portMap[location.Scheme]; ok {
|
|
|
+ if _, _, err := net.SplitHostPort(location.Host); err != nil {
|
|
|
+ return net.JoinHostPort(location.Host, portMap[location.Scheme])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return location.Host
|
|
|
+}
|
|
|
+
|
|
|
// DialConfig opens a new client connection to a WebSocket with a config.
|
|
|
func DialConfig(config *Config) (ws *Conn, err error) {
|
|
|
var client net.Conn
|
|
|
@@ -75,10 +89,10 @@ func DialConfig(config *Config) (ws *Conn, err error) {
|
|
|
}
|
|
|
switch config.Location.Scheme {
|
|
|
case "ws":
|
|
|
- client, err = net.Dial("tcp", config.Location.Host)
|
|
|
+ client, err = net.Dial("tcp", parseAuthority(config.Location))
|
|
|
|
|
|
case "wss":
|
|
|
- client, err = tls.Dial("tcp", config.Location.Host, config.TlsConfig)
|
|
|
+ client, err = tls.Dial("tcp", parseAuthority(config.Location), config.TlsConfig)
|
|
|
|
|
|
default:
|
|
|
err = ErrBadScheme
|