http_proxy_cert_cache.go 586 B

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