Compare commits

..

No commits in common. "adb4d3d33d1e174e252acf1d55a07758a6c3d0e1" and "5507467fb3789964bc88c63f513df6cd7ecf4f88" have entirely different histories.

3 changed files with 10 additions and 4 deletions

View File

@ -42,6 +42,7 @@ type Monitor struct {
// For http // For http
url string url string
header http.Header header http.Header
host string
failedTimes uint64 failedTimes uint64
statusOK bool statusOK bool
statusNormalFn func() statusNormalFn func()
@ -74,7 +75,7 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
url = s + cfg.Path url = s + cfg.Path
} }
header := make(http.Header) header := make(http.Header)
for _, h := range cfg.HTTPHeaders { for _, h := range cfg.Headers {
header.Set(h.Name, h.Value) header.Set(h.Name, h.Value)
} }
@ -86,6 +87,7 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
addr: addr, addr: addr,
url: url, url: url,
header: header, header: header,
host: cfg.HostHeaderRewrite,
statusOK: false, statusOK: false,
statusNormalFn: statusNormalFn, statusNormalFn: statusNormalFn,
statusFailedFn: statusFailedFn, statusFailedFn: statusFailedFn,
@ -170,7 +172,7 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
return err return err
} }
req.Header = monitor.header req.Header = monitor.header
req.Host = monitor.header.Get("Host") req.Host = monitor.host
resp, err := http.DefaultClient.Do(req) resp, err := http.DefaultClient.Do(req)
if err != nil { if err != nil {
return err return err

View File

@ -217,9 +217,10 @@ healthCheck.intervalSeconds = 10
healthCheck.maxFailed = 3 healthCheck.maxFailed = 3
healthCheck.timeoutSeconds = 3 healthCheck.timeoutSeconds = 3
# set health check headers # set health check headers
healthCheck.httpheaders=[ healthCheck.headers=[
{ name = "x-from-where", value = "frp" } { name = "x-from-where", value = "frp" }
] ]
healthCheck.hostHeaderRewrite = "example.com"
[[proxies]] [[proxies]]
name = "web02" name = "web02"

View File

@ -99,7 +99,10 @@ type HealthCheckConfig struct {
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
// Headers specifies the headers to send health checks to if the // Headers specifies the headers to send health checks to if the
// health check type is "http". // health check type is "http".
HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"` Headers []HTTPHeader `json:"headers,omitempty"`
// HostHeaderRewrite specifies the request host to send health checks to if the
// health check type is "http".
HostHeaderRewrite string `json:"hostHeaderRewrite,omitempty"`
} }
type DomainConfig struct { type DomainConfig struct {