1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
package http_proxy
import (
"crypto/tls"
"fmt"
"sync"
)
var (
certCache = make(map[string]*tls.Certificate)
certLock = &sync.Mutex{}
)
func keyFor(domain string, port int) string {
return fmt.Sprintf("%s:%d", domain, port)
}
func getCachedCert(domain string, port int) *tls.Certificate {
certLock.Lock()
defer certLock.Unlock()
if cert, found := certCache[keyFor(domain, port)]; found {
return cert
}
return nil
}
func setCachedCert(domain string, port int, cert *tls.Certificate) {
certLock.Lock()
defer certLock.Unlock()
certCache[keyFor(domain, port)] = cert
}
|