Skip to content

Commit 3f3e394

Browse files
wstrmgaryburd
authored andcommitted
Update cloneTLSConfig to use Go 1.8 Config.Clone method
1 parent 9acaa68 commit 3f3e394

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

client.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -389,32 +389,3 @@ func (d *Dialer) Dial(urlStr string, requestHeader http.Header) (*Conn, *http.Re
389389
netConn = nil // to avoid close in defer.
390390
return conn, resp, nil
391391
}
392-
393-
// cloneTLSConfig clones all public fields except the fields
394-
// SessionTicketsDisabled and SessionTicketKey. This avoids copying the
395-
// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a
396-
// config in active use.
397-
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
398-
if cfg == nil {
399-
return &tls.Config{}
400-
}
401-
return &tls.Config{
402-
Rand: cfg.Rand,
403-
Time: cfg.Time,
404-
Certificates: cfg.Certificates,
405-
NameToCertificate: cfg.NameToCertificate,
406-
GetCertificate: cfg.GetCertificate,
407-
RootCAs: cfg.RootCAs,
408-
NextProtos: cfg.NextProtos,
409-
ServerName: cfg.ServerName,
410-
ClientAuth: cfg.ClientAuth,
411-
ClientCAs: cfg.ClientCAs,
412-
InsecureSkipVerify: cfg.InsecureSkipVerify,
413-
CipherSuites: cfg.CipherSuites,
414-
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
415-
ClientSessionCache: cfg.ClientSessionCache,
416-
MinVersion: cfg.MinVersion,
417-
MaxVersion: cfg.MaxVersion,
418-
CurvePreferences: cfg.CurvePreferences,
419-
}
420-
}

client_clone.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build go1.8
6+
7+
package websocket
8+
9+
import "crypto/tls"
10+
11+
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
12+
if cfg == nil {
13+
return &tls.Config{}
14+
}
15+
return cfg.Clone()
16+
}

client_clone_legacy.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !go1.8
6+
7+
package websocket
8+
9+
import "crypto/tls"
10+
11+
// cloneTLSConfig clones all public fields except the fields
12+
// SessionTicketsDisabled and SessionTicketKey. This avoids copying the
13+
// sync.Mutex in the sync.Once and makes it safe to call cloneTLSConfig on a
14+
// config in active use.
15+
func cloneTLSConfig(cfg *tls.Config) *tls.Config {
16+
if cfg == nil {
17+
return &tls.Config{}
18+
}
19+
return &tls.Config{
20+
Rand: cfg.Rand,
21+
Time: cfg.Time,
22+
Certificates: cfg.Certificates,
23+
NameToCertificate: cfg.NameToCertificate,
24+
GetCertificate: cfg.GetCertificate,
25+
RootCAs: cfg.RootCAs,
26+
NextProtos: cfg.NextProtos,
27+
ServerName: cfg.ServerName,
28+
ClientAuth: cfg.ClientAuth,
29+
ClientCAs: cfg.ClientCAs,
30+
InsecureSkipVerify: cfg.InsecureSkipVerify,
31+
CipherSuites: cfg.CipherSuites,
32+
PreferServerCipherSuites: cfg.PreferServerCipherSuites,
33+
ClientSessionCache: cfg.ClientSessionCache,
34+
MinVersion: cfg.MinVersion,
35+
MaxVersion: cfg.MaxVersion,
36+
CurvePreferences: cfg.CurvePreferences,
37+
}
38+
}

0 commit comments

Comments
 (0)