add header for http healthcheck
This commit is contained in:
parent
f095130823
commit
1c173839db
@ -42,6 +42,7 @@ type Monitor struct {
|
||||
// For http
|
||||
url string
|
||||
header http.Header
|
||||
host string
|
||||
failedTimes uint64
|
||||
statusOK bool
|
||||
statusNormalFn func()
|
||||
@ -74,8 +75,8 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
|
||||
url = s + cfg.Path
|
||||
}
|
||||
header := make(http.Header)
|
||||
for k, v := range cfg.Headers.Set {
|
||||
header.Set(k, v)
|
||||
for _, h := range cfg.Headers {
|
||||
header.Set(h.Name, h.Value)
|
||||
}
|
||||
|
||||
return &Monitor{
|
||||
@ -86,6 +87,7 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
|
||||
addr: addr,
|
||||
url: url,
|
||||
header: header,
|
||||
host: cfg.HostHeaderRewrite,
|
||||
statusOK: false,
|
||||
statusNormalFn: statusNormalFn,
|
||||
statusFailedFn: statusFailedFn,
|
||||
@ -170,10 +172,7 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
req.Header = monitor.header
|
||||
for k, v := range req.Header {
|
||||
fmt.Println(k, v)
|
||||
|
||||
}
|
||||
req.Host = monitor.host
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -217,7 +217,11 @@ healthCheck.intervalSeconds = 10
|
||||
healthCheck.maxFailed = 3
|
||||
healthCheck.timeoutSeconds = 3
|
||||
# set health check headers
|
||||
healthCheck.headers.set.Host= = "example.com"
|
||||
healthCheck.headers=[
|
||||
{ name = "x-from-where", value = "frp" }
|
||||
]
|
||||
healthCheck.hostHeaderRewrite = "example.com"
|
||||
|
||||
[[proxies]]
|
||||
name = "web02"
|
||||
type = "https"
|
||||
|
@ -129,3 +129,8 @@ type HTTPPluginOptions struct {
|
||||
type HeaderOperations struct {
|
||||
Set map[string]string `json:"set,omitempty"`
|
||||
}
|
||||
|
||||
type HTTPHeader struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
@ -99,7 +99,10 @@ type HealthCheckConfig struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
// Headers specifies the headers to send health checks to if the
|
||||
// health check type is "http".
|
||||
Headers HeaderOperations `json:"headers,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 {
|
||||
|
Loading…
Reference in New Issue
Block a user