【修复】修复部署到阿里云waf失败导致panic

【调整】https监控禁止重定向
【调整】https监控增加失败重试3次
This commit is contained in:
v-me-50
2025-07-30 09:46:10 +08:00
parent e2d0986616
commit 533df1b4b7
5 changed files with 88 additions and 42 deletions

View File

@@ -132,18 +132,34 @@ func CheckHttps(target string, advanceDay int) (result *CertInfo, err error) {
// 构建 HTTP 客户端
client := &http.Client{
// 禁止重定向,确保获取到原始证书链
CheckRedirect: func(req *http.Request, via []*http.Request) error {
// 返回错误以阻止重定向
return http.ErrUseLastResponse
},
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
Timeout: 5 * time.Second,
//Timeout: 5 * time.Second,
}
// 发送请求
resp, err := client.Get(url)
if err != nil {
return nil, fmt.Errorf("无法建立 HTTPS 连接:%v", err)
// 如果无法建立 HTTPS 连接重试3次
retryCount := 3
for i := 0; i < retryCount; i++ {
resp, err = client.Get(url)
if err == nil {
break // 成功则退出重试
}
time.Sleep(1 * time.Second) // 等待1秒后重试
}
if err != nil {
return nil, fmt.Errorf("无法建立 HTTPS 连接:%v", err)
}
}
defer resp.Body.Close()