Compare commits

..

3 Commits

Author SHA1 Message Date
fatedier
9e4e9e377f update release notes 2024-03-20 15:02:20 +08:00
Kaive Young
bc5fb91c05
add header for http healthcheck (#4085) 2024-03-20 14:58:03 +08:00
fatedier
002831ea82
add doc for port range mapping (#4081) 2024-03-19 13:22:29 +08:00
5 changed files with 24 additions and 2 deletions

View File

@ -16,6 +16,8 @@
This will create 8 proxies such as `tcp-6000, tcp-6001, ... tcp-6007`.
* Health check supports custom request headers.
### Fixes
* Fix the issue of incorrect interval time for rotating the log by day.

View File

@ -40,8 +40,8 @@ type Monitor struct {
addr string
// For http
url string
url string
header http.Header
failedTimes uint64
statusOK bool
statusNormalFn func()
@ -73,6 +73,11 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
}
url = s + cfg.Path
}
header := make(http.Header)
for _, h := range cfg.HTTPHeaders {
header.Set(h.Name, h.Value)
}
return &Monitor{
checkType: cfg.Type,
interval: time.Duration(cfg.IntervalSeconds) * time.Second,
@ -80,6 +85,7 @@ func NewMonitor(ctx context.Context, cfg v1.HealthCheckConfig, addr string,
maxFailedTimes: cfg.MaxFailed,
addr: addr,
url: url,
header: header,
statusOK: false,
statusNormalFn: statusNormalFn,
statusFailedFn: statusFailedFn,
@ -163,6 +169,8 @@ func (monitor *Monitor) doHTTPCheck(ctx context.Context) error {
if err != nil {
return err
}
req.Header = monitor.header
req.Host = monitor.header.Get("Host")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err

View File

@ -216,6 +216,10 @@ healthCheck.path = "/status"
healthCheck.intervalSeconds = 10
healthCheck.maxFailed = 3
healthCheck.timeoutSeconds = 3
# set health check headers
healthCheck.httpHeaders=[
{ name = "x-from-where", value = "frp" }
]
[[proxies]]
name = "web02"

View File

@ -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"`
}

View File

@ -97,6 +97,9 @@ type HealthCheckConfig struct {
// Path specifies the path to send health checks to if the
// health check type is "http".
Path string `json:"path,omitempty"`
// HTTPHeaders specifies the headers to send with the health request, if
// the health check type is "http".
HTTPHeaders []HTTPHeader `json:"httpHeaders,omitempty"`
}
type DomainConfig struct {