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