Skip to content

Commit

Permalink
Fix tls=true didn't work with host without port.
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Nov 30, 2017
1 parent cd4cb90 commit 04e90ad
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ func (cfg *Config) normalize() error {
cfg.Addr = ensureHavePort(cfg.Addr)
}

if cfg.tls != nil {
if cfg.tls.ServerName == "" && !cfg.tls.InsecureSkipVerify {
host, _, err := net.SplitHostPort(cfg.Addr)
if err == nil {
tlsConfig.ServerName = host
}
}
}

return nil
}

Expand Down Expand Up @@ -521,10 +530,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
if boolValue {
cfg.TLSConfig = "true"
cfg.tls = &tls.Config{}
host, _, err := net.SplitHostPort(cfg.Addr)
if err == nil {
cfg.tls.ServerName = host
}
} else {
cfg.TLSConfig = "false"
}
Expand All @@ -538,13 +543,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
}

if tlsConfig := getTLSConfigClone(name); tlsConfig != nil {
if len(tlsConfig.ServerName) == 0 && !tlsConfig.InsecureSkipVerify {
host, _, err := net.SplitHostPort(cfg.Addr)
if err == nil {
tlsConfig.ServerName = host
}
}

cfg.TLSConfig = name
cfg.tls = tlsConfig
} else {
Expand Down

0 comments on commit 04e90ad

Please sign in to comment.