Skip to content

Commit

Permalink
support force rewrite health check url
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Sep 9, 2022
1 parent dc11229 commit b9600a4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -206,6 +208,7 @@ func UnmarshalRawConfig(buf []byte) (*RawConfig, error) {
LogLevel: log.INFO,
UseRemoteDnsDefault: true,
UseSystemDnsDial: false,
HealthCheckURL: "",
HealthCheckLazyDefault: true,
TouchAfterLazyPassNum: 0,
PreResolveProcessName: false,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions hub/route/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b9600a4

Please sign in to comment.