diff --git a/adapter/adapter.go b/adapter/adapter.go index b86385417e..71ec56d071 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -130,6 +130,10 @@ func (p *Proxy) URLTest(ctx context.Context, url string) (t uint16, err error) { } }() + if len(healthCheckURL) > 0 { + url = healthCheckURL + } + addr, err := urlToMetadata(url) if err != nil { return @@ -210,3 +214,13 @@ func urlToMetadata(rawURL string) (addr C.Metadata, err error) { } return } + +var healthCheckURL string + +func HealthCheckURL() string { + return healthCheckURL +} + +func SetHealthCheckURL(newHealthCheckURL string) { + healthCheckURL = newHealthCheckURL +} diff --git a/config/config.go b/config/config.go index 0d16d68605..2951a818d1 100644 --- a/config/config.go +++ b/config/config.go @@ -36,6 +36,7 @@ type General struct { RoutingMark int `json:"-"` UseRemoteDnsDefault bool `json:"use-remote-dns-default"` UseSystemDnsDial bool `json:"use-system-dns-dial"` + HealthCheckURL string `json:"health-check-url"` HealthCheckLazyDefault bool `json:"health-check-lazy-default"` TouchAfterLazyPassNum int `json:"touch-after-lazy-pass-num"` PreResolveProcessName bool `json:"pre-resolve-process-name"` @@ -170,6 +171,7 @@ type RawConfig struct { RoutingMark int `yaml:"routing-mark"` UseRemoteDnsDefault bool `yaml:"use-remote-dns-default"` UseSystemDnsDial bool `yaml:"use-system-dns-dial"` + HealthCheckURL string `yaml:"health-check-url"` HealthCheckLazyDefault bool `yaml:"health-check-lazy-default"` TouchAfterLazyPassNum int `yaml:"touch-after-lazy-pass-num"` PreResolveProcessName bool `yaml:"pre-resolve-process-name"` @@ -206,6 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) { LogLevel: log.INFO, UseRemoteDnsDefault: true, UseSystemDnsDial: false, + HealthCheckURL: "", HealthCheckLazyDefault: true, TouchAfterLazyPassNum: 0, PreResolveProcessName: false, @@ -342,6 +345,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) { RoutingMark: cfg.RoutingMark, UseRemoteDnsDefault: cfg.UseRemoteDnsDefault, UseSystemDnsDial: cfg.UseSystemDnsDial, + HealthCheckURL: cfg.HealthCheckURL, HealthCheckLazyDefault: cfg.HealthCheckLazyDefault, TouchAfterLazyPassNum: cfg.TouchAfterLazyPassNum, PreResolveProcessName: cfg.PreResolveProcessName, diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 51295a824f..3a7fb8c9e4 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -113,6 +113,7 @@ func GetGeneral() *config.General { IPv6: !resolver.DisableIPv6, UseRemoteDnsDefault: dns.UseRemoteDnsDefault(), UseSystemDnsDial: dns.UseSystemDnsDial(), + HealthCheckURL: adapter.HealthCheckURL(), HealthCheckLazyDefault: provider.HealthCheckLazyDefault(), TouchAfterLazyPassNum: provider.TouchAfterLazyPassNum(), PreResolveProcessName: tunnel.PreResolveProcessName(), @@ -227,6 +228,7 @@ func updateGeneral(general *config.General, force bool) { resolver.DisableIPv6 = !general.IPv6 dns.SetUseRemoteDnsDefault(general.UseRemoteDnsDefault) dns.SetUseSystemDnsDial(general.UseSystemDnsDial) + adapter.SetHealthCheckURL(general.HealthCheckURL) provider.SetHealthCheckLazyDefault(general.HealthCheckLazyDefault) provider.SetTouchAfterLazyPassNum(general.TouchAfterLazyPassNum) tunnel.SetPreResolveProcessName(general.PreResolveProcessName) diff --git a/hub/route/configs.go b/hub/route/configs.go index 7304c5e55c..0d121dd85e 100644 --- a/hub/route/configs.go +++ b/hub/route/configs.go @@ -4,6 +4,7 @@ import ( "net/http" "path/filepath" + "github.com/Dreamacro/clash/adapter" "github.com/Dreamacro/clash/adapter/provider" "github.com/Dreamacro/clash/component/resolver" "github.com/Dreamacro/clash/config" @@ -45,6 +46,7 @@ type configSchema struct { IPv6 *bool `json:"ipv6"` UseRemoteDnsDefault *bool `json:"use-remote-dns-default"` UseSystemDnsDial *bool `json:"use-system-dns-dial"` + HealthCheckURL *string `json:"health-check-url"` HealthCheckLazyDefault *bool `json:"health-check-lazy-default"` TouchAfterLazyPassNum *int `json:"touch-after-lazy-pass-num"` PreResolveProcessName *bool `json:"pre-resolve-process-name"` @@ -151,6 +153,10 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) { dns.SetUseSystemDnsDial(*general.UseSystemDnsDial) } + if general.HealthCheckURL != nil { + adapter.SetHealthCheckURL(*general.HealthCheckURL) + } + if general.HealthCheckLazyDefault != nil { provider.SetHealthCheckLazyDefault(*general.HealthCheckLazyDefault) }