Skip to content

Commit df50417

Browse files
feat(health): pass HCH_SERVER and HCH_SOCKS_PORT to custom tester
Custom check binaries now receive the proxy host and port number as separate env vars alongside HCH_PROXY_ADDR, so testers can connect directly without parsing the URL themselves. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3f8dce8 commit df50417

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

docs/run-json.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ The binary receives these env vars:
225225
| Var | Value |
226226
|---|---|
227227
| `HCH_PROXY_ADDR` | `socks5://host:port` (the client SOCKS proxy) |
228+
| `HCH_SERVER` | proxy host (e.g. `127.0.0.1`) |
229+
| `HCH_SOCKS_PORT` | proxy port number (e.g. `1080`) |
228230
| `HCH_TIMEOUT` | timeout in seconds |
229231

230232
Stdout/stderr from the binary appears in the result `Extra` field (truncated to 200 chars).

internal/health/health.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,23 @@ func Run(ctx context.Context, cfg Config) ([]Result, error) {
243243
// Environment variables passed to the custom tester:
244244
//
245245
// HCH_PROXY_ADDR socks5://host:port (the client SOCKS proxy)
246+
// HCH_SOCKS_PORT port number only (e.g. "1080")
247+
// HCH_SERVER proxy host (e.g. "127.0.0.1")
246248
// HCH_TIMEOUT timeout in seconds
247249
func runCustomCheck(ctx context.Context, path string, cfg Config) (Result, error) {
248250
timeoutCtx, cancel := context.WithTimeout(ctx, cfg.Timeout)
249251
defer cancel()
250252

251253
cmd := exec.CommandContext(timeoutCtx, path)
252-
cmd.Env = append(cmd.Environ(),
253-
"HCH_PROXY_ADDR="+cfg.ProxyAddr,
254-
"HCH_TIMEOUT="+strconv.Itoa(int(cfg.Timeout.Seconds())),
255-
)
254+
env := []string{
255+
"HCH_PROXY_ADDR=" + cfg.ProxyAddr,
256+
"HCH_TIMEOUT=" + strconv.Itoa(int(cfg.Timeout.Seconds())),
257+
}
258+
if u, err := url.Parse(cfg.ProxyAddr); err == nil {
259+
host, port, _ := net.SplitHostPort(u.Host)
260+
env = append(env, "HCH_SERVER="+host, "HCH_SOCKS_PORT="+port)
261+
}
262+
cmd.Env = append(cmd.Environ(), env...)
256263

257264
out, err := cmd.CombinedOutput()
258265
extra := strings.TrimSpace(string(out))

0 commit comments

Comments
 (0)