Skip to content

Commit 04e90ad

Browse files
committed
Fix tls=true didn't work with host without port.
Fixes #717
1 parent cd4cb90 commit 04e90ad

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

dsn.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ func (cfg *Config) normalize() error {
9494
cfg.Addr = ensureHavePort(cfg.Addr)
9595
}
9696

97+
if cfg.tls != nil {
98+
if cfg.tls.ServerName == "" && !cfg.tls.InsecureSkipVerify {
99+
host, _, err := net.SplitHostPort(cfg.Addr)
100+
if err == nil {
101+
tlsConfig.ServerName = host
102+
}
103+
}
104+
}
105+
97106
return nil
98107
}
99108

@@ -521,10 +530,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
521530
if boolValue {
522531
cfg.TLSConfig = "true"
523532
cfg.tls = &tls.Config{}
524-
host, _, err := net.SplitHostPort(cfg.Addr)
525-
if err == nil {
526-
cfg.tls.ServerName = host
527-
}
528533
} else {
529534
cfg.TLSConfig = "false"
530535
}
@@ -538,13 +543,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
538543
}
539544

540545
if tlsConfig := getTLSConfigClone(name); tlsConfig != nil {
541-
if len(tlsConfig.ServerName) == 0 && !tlsConfig.InsecureSkipVerify {
542-
host, _, err := net.SplitHostPort(cfg.Addr)
543-
if err == nil {
544-
tlsConfig.ServerName = host
545-
}
546-
}
547-
548546
cfg.TLSConfig = name
549547
cfg.tls = tlsConfig
550548
} else {

0 commit comments

Comments
 (0)