@@ -16,11 +16,13 @@ import (
16
16
"fmt"
17
17
"io"
18
18
"strings"
19
+ "sync"
19
20
"sync/atomic"
20
21
"time"
21
22
)
22
23
23
24
var (
25
+ tlsConfigLock sync.RWMutex
24
26
tlsConfigRegister map[string]*tls.Config // Register for custom tls.Configs
25
27
)
26
28
@@ -54,19 +56,32 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
54
56
return fmt.Errorf("key '%s' is reserved", key)
55
57
}
56
58
59
+ tlsConfigLock.Lock()
57
60
if tlsConfigRegister == nil {
58
61
tlsConfigRegister = make(map[string]*tls.Config)
59
62
}
60
63
61
64
tlsConfigRegister[key] = config
65
+ tlsConfigLock.Unlock()
62
66
return nil
63
67
}
64
68
65
69
// DeregisterTLSConfig removes the tls.Config associated with key.
66
70
func DeregisterTLSConfig(key string) {
71
+ tlsConfigLock.Lock()
67
72
if tlsConfigRegister != nil {
68
73
delete(tlsConfigRegister, key)
69
74
}
75
+ tlsConfigLock.Unlock()
76
+ }
77
+
78
+ func getTLSConfigClone(key string) (config *tls.Config) {
79
+ tlsConfigLock.RLock()
80
+ if v, ok := tlsConfigRegister[key]; ok {
81
+ config = cloneTLSConfig(v)
82
+ }
83
+ tlsConfigLock.RUnlock()
84
+ return
70
85
}
71
86
72
87
// Returns the bool value of the input.
@@ -745,6 +760,7 @@ func escapeStringQuotes(buf []byte, v string) []byte {
745
760
/******************************************************************************
746
761
* Sync utils *
747
762
******************************************************************************/
763
+
748
764
// noCopy may be embedded into structs which must not be copied
749
765
// after the first use.
750
766
//
0 commit comments