MCPcopy
hub / github.com/sourcegraph/checkup / checkDown

Method checkDown

check/http/http.go:179–202  ·  view source on GitHub ↗

checkDown checks whether the endpoint is down based on resp and the configuration of c. It returns a non-nil error if down. Note that it does not check for degraded response.

(resp *http.Response)

Source from the content-addressed store, hash-verified

177// the configuration of c. It returns a non-nil error if down.
178// Note that it does not check for degraded response.
179func (c Checker) checkDown(resp *http.Response) error {
180 // Check status code
181 if resp.StatusCode != c.UpStatus {
182 return fmt.Errorf("response status %s", resp.Status)
183 }
184
185 // Check response body
186 if c.MustContain == "" && c.MustNotContain == "" {
187 return nil
188 }
189 bodyBytes, err := ioutil.ReadAll(resp.Body)
190 if err != nil {
191 return fmt.Errorf("reading response body: %v", err)
192 }
193 body := string(bodyBytes)
194 if c.MustContain != "" && !strings.Contains(body, c.MustContain) {
195 return fmt.Errorf("response does not contain '%s'", c.MustContain)
196 }
197 if c.MustNotContain != "" && strings.Contains(body, c.MustNotContain) {
198 return fmt.Errorf("response contains '%s'", c.MustNotContain)
199 }
200
201 return nil
202}
203
204// DefaultHTTPClient is used when no other http.Client
205// is specified on a Checker.

Callers 1

doChecksMethod · 0.95

Implementers 6

fakecheckup_test.go
Checkercheck/http/http.go
Checkercheck/dns/dns.go
Checkercheck/exec/exec.go
Checkercheck/tls/tls.go
Checkercheck/tcp/tcp.go

Calls

no outgoing calls

Tested by

no test coverage detected