Skip to content

Commit 2f2f4da

Browse files
authored
Merge pull request #373 from kevinxmorales/kevinxmorales/add-tls-options
Add servername and min tls version to tls config
2 parents b9b0f4b + 2094d67 commit 2f2f4da

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

url.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func ParseURL(str string) (opt ClientOption, err error) {
2525
}
2626
opt.InitAddress = []string{strings.TrimSpace(u.Path)}
2727
case "rediss":
28-
opt.TLSConfig = &tls.Config{}
28+
opt.TLSConfig = &tls.Config{
29+
MinVersion: tls.VersionTLS12,
30+
}
2931
case "redis":
3032
default:
3133
return opt, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
@@ -42,6 +44,9 @@ func ParseURL(str string) (opt ClientOption, err error) {
4244
port = "6379"
4345
}
4446
opt.InitAddress = []string{net.JoinHostPort(host, port)}
47+
if opt.TLSConfig != nil {
48+
opt.TLSConfig.ServerName = host
49+
}
4550
}
4651
if u.User != nil {
4752
opt.Username = u.User.Username()

url_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func TestParseURL(t *testing.T) {
5757
if opt, err := ParseURL("redis://?master_set=0"); opt.Sentinel.MasterSet != "0" {
5858
t.Fatalf("unexpected %v %v", opt, err)
5959
}
60+
if opt, err := ParseURL("rediss://myhost:6379"); err != nil || opt.TLSConfig.ServerName != "myhost" {
61+
t.Fatalf("unexpected %v %v", opt, err)
62+
}
6063
}
6164

6265
func TestMustParseURL(t *testing.T) {

0 commit comments

Comments
 (0)