zoraxy-waf/health.go
cclohmar 16761613bb fix: redirect preservation, health check, Content-Length, UI simplification
- health.go: treat any HTTP response as reachable (only connection errors fail)
- main.go: CheckRedirect in handleReturn to preserve 302 + Set-Cookie
- middleware.go: Content-Length for POST/PUT/PATCH bodies, CheckRedirect
  in forwardToWAF and forwardToReturn
- web/: replace stats panel with 3-state WAF indicator (DISABLED/ENABLED/FAILED)
- README: update defaults, architecture, health check docs
- .agents.md: update verified status for Wallarm integration
2026-08-08 14:53:12 +00:00

33 lines
673 B
Go

package main
import (
"log"
"net/http"
"time"
)
// startHealthCheck runs a periodic health check against the WAF.
// It updates the circuit breaker based on WAF reachability.
func startHealthCheck() {
go func() {
for {
cfg := getConfig()
interval := time.Duration(cfg.HealthInterval) * time.Second
if interval < 1*time.Second {
interval = 5 * time.Second
}
client := &http.Client{Timeout: 2 * time.Second}
resp, err := client.Head(cfg.WAFURL + "/")
if err != nil {
log.Printf("WAF health check FAILED: %v", err)
breaker.RecordFailure()
} else {
resp.Body.Close()
breaker.RecordSuccess()
}
time.Sleep(interval)
}
}()
}