mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-08 03:00:26 +08:00
健康检查支持UserAgent和是否基础请求设置
This commit is contained in:
@@ -10,8 +10,10 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/lists"
|
"github.com/iwind/TeaGo/lists"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -167,11 +169,28 @@ func (this *HealthCheckExecutor) checkNode(healthCheckConfig *serverconfigs.Heal
|
|||||||
result.NodeAddr = "[" + result.NodeAddr + "]"
|
result.NodeAddr = "[" + result.NodeAddr + "]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(healthCheckConfig.URL) == 0 {
|
||||||
|
healthCheckConfig.URL = "http://${host}/"
|
||||||
|
}
|
||||||
|
|
||||||
url := strings.ReplaceAll(healthCheckConfig.URL, "${host}", result.NodeAddr)
|
url := strings.ReplaceAll(healthCheckConfig.URL, "${host}", result.NodeAddr)
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if len(healthCheckConfig.UserAgent) > 0 {
|
||||||
|
req.Header.Set("User-Agent", healthCheckConfig.UserAgent)
|
||||||
|
} else {
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36")
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := nodeutils.EncryptData(result.Node.UniqueId, result.Node.Secret, maps.Map{
|
||||||
|
"onlyBasicRequest": healthCheckConfig.OnlyBasicRequest,
|
||||||
|
}, 300)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Set(serverconfigs.HealthCheckHeaderName, key)
|
||||||
|
|
||||||
timeout := 5 * time.Second
|
timeout := 5 * time.Second
|
||||||
if healthCheckConfig.Timeout != nil {
|
if healthCheckConfig.Timeout != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user