Skip to content

Commit

Permalink
fix: using extra valid status codes when response status code greater…
Browse files Browse the repository at this point in the history
… than 400 (#3986)
  • Loading branch information
fengxsong committed Sep 25, 2023
1 parent a636615 commit 344296e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions staging/src/github.com/labring/lvscare/care/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *httpProber) RegisterFlags(fs *pflag.FlagSet) {
fs.StringVar(&p.Method, "health-req-method", "GET", "http request method")
fs.StringVar(&p.Body, "health-req-body", "", "body to send for health checker")
fs.StringToStringVar(&p.Headers, "health-req-headers", map[string]string{}, "http request headers")
fs.IntSliceVar(&p.ValidStatusCodes, "health-status", []int{}, "valid status codes")
fs.IntSliceVar(&p.ValidStatusCodes, "health-status", []int{}, "extra valid status codes greater than 400")
fs.BoolVar(&p.InsecureSkipVerify, "health-insecure-skip-verify", true, "skip verify insecure request")
fs.DurationVar(&p.timeout, "health-timeout", 10*time.Second, "http probe timeout")
}
Expand Down Expand Up @@ -114,13 +114,10 @@ func (p *httpProber) Probe(host, port string) error {
defer func() {
_, _ = io.Copy(io.Discard, resp.Body)
}()
if p.validStatus.Len() > 0 {
if p.validStatus.Has(resp.StatusCode) {
if resp.StatusCode/100 >= 4 {
if p.validStatus.Len() > 0 && p.validStatus.Has(resp.StatusCode) {
return nil
}
return fmt.Errorf("invalid status code %d", resp.StatusCode)
}
if resp.StatusCode/100 >= 4 {
return fmt.Errorf("unexpected status code %d", resp.StatusCode)
}
return nil
Expand Down

0 comments on commit 344296e

Please sign in to comment.