Skip to content

Commit

Permalink
fix: don't fetch response after the reader is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 16, 2023
1 parent c916c0e commit beaabcf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions checks/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,17 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg.
sslExpiration.WithLabelValues(check.URL).Set(age.Hours() * 24)
}

body, _ = response.AsString()

data := map[string]interface{}{
"code": status,
"headers": response.Header,
"elapsed": time.Since(start),
"content": body,
"sslAge": utils.Deref(age),
"json": make(map[string]any),
}

if response.IsJSON() {
json, err := response.AsJSON()
data["json"] = json
if err == nil {
data["json"] = json
if check.ResponseJSONContent != nil && check.ResponseJSONContent.Path != "" {
Expand All @@ -221,6 +219,9 @@ func (c *HTTPChecker) Check(ctx *context.Context, extConfig external.Check) pkg.
} else {
ctx.Tracef("ignoring invalid json response %v", err)
}
} else {
responseBody, _ := response.AsString()
data["content"] = responseBody
}

result.AddData(data)
Expand Down

0 comments on commit beaabcf

Please sign in to comment.