chore: optimize tls cert expire check (#3394)
Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
parent
29ab308475
commit
6d21c53acc
|
|
@ -459,7 +459,7 @@ func (proxy *Proxy) handleHTTPS(w http.ResponseWriter, r *http.Request) {
|
||||||
proxy.cacheRWMutex.RLock()
|
proxy.cacheRWMutex.RLock()
|
||||||
cached, hit := proxy.certCache.Get(cacheKey)
|
cached, hit := proxy.certCache.Get(cacheKey)
|
||||||
proxy.cacheRWMutex.RUnlock()
|
proxy.cacheRWMutex.RUnlock()
|
||||||
if hit && time.Now().Before(cached.(*tls.Certificate).Leaf.NotAfter) { // If cache hit and the cert is not expired
|
if hit && time.Now().Before(cached.(*tls.Certificate).Leaf.NotAfter.Add(-time.Hour)) { // If cache hit and the cert is not expired
|
||||||
logger.Debugf("TLS cert cache hit, cacheKey = <%s>", cacheKey)
|
logger.Debugf("TLS cert cache hit, cacheKey = <%s>", cacheKey)
|
||||||
return cached.(*tls.Certificate), nil
|
return cached.(*tls.Certificate), nil
|
||||||
}
|
}
|
||||||
|
|
@ -629,7 +629,7 @@ func (proxy *Proxy) shouldUseDragonfly(req *http.Request) bool {
|
||||||
if strings.Contains(rule.Redirect, "/") {
|
if strings.Contains(rule.Redirect, "/") {
|
||||||
u, err := url.Parse(rule.Regx.ReplaceAllString(req.URL.String(), rule.Redirect))
|
u, err := url.Parse(rule.Regx.ReplaceAllString(req.URL.String(), rule.Redirect))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed to rewrite url", err)
|
logger.Errorf("failed to rewrite url: %s", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
req.URL = u
|
req.URL = u
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue