@@ -16,11 +16,13 @@ import (
1616 "fmt"
1717 "io"
1818 "strings"
19+ "sync"
1920 "sync/atomic"
2021 "time"
2122)
2223
2324var (
25+ tlsConfigLock sync.RWMutex
2426 tlsConfigRegister map [string ]* tls.Config // Register for custom tls.Configs
2527)
2628
@@ -54,19 +56,32 @@ func RegisterTLSConfig(key string, config *tls.Config) error {
5456 return fmt .Errorf ("key '%s' is reserved" , key )
5557 }
5658
59+ tlsConfigLock .Lock ()
5760 if tlsConfigRegister == nil {
5861 tlsConfigRegister = make (map [string ]* tls.Config )
5962 }
6063
6164 tlsConfigRegister [key ] = config
65+ tlsConfigLock .Unlock ()
6266 return nil
6367}
6468
6569// DeregisterTLSConfig removes the tls.Config associated with key.
6670func DeregisterTLSConfig (key string ) {
71+ tlsConfigLock .Lock ()
6772 if tlsConfigRegister != nil {
6873 delete (tlsConfigRegister , key )
6974 }
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
7085}
7186
7287// Returns the bool value of the input.
@@ -745,6 +760,7 @@ func escapeStringQuotes(buf []byte, v string) []byte {
745760/******************************************************************************
746761* Sync utils *
747762******************************************************************************/
763+
748764// noCopy may be embedded into structs which must not be copied
749765// after the first use.
750766//
0 commit comments