From 04e90ad3891e7fc11fc0d8fc15a71f531cbf5a73 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Thu, 30 Nov 2017 23:16:18 +0900 Subject: [PATCH] Fix tls=true didn't work with host without port. Fixes #717 --- dsn.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/dsn.go b/dsn.go index f5ea0d470..5a02530a1 100644 --- a/dsn.go +++ b/dsn.go @@ -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 } @@ -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" } @@ -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 {