Skip to content

Commit

Permalink
Ensure keep-alive is not used in http_response input.
Browse files Browse the repository at this point in the history
Using Keep-Alive would change the timing for already established
connections.  Previous to this commit, Keep-Alive worked only when using
a response_string_match due to failure to close the request body.
  • Loading branch information
danielnelson committed May 10, 2017
1 parent a1446a6 commit 17d883c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/inputs/http_response/http_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func (h *HTTPResponse) createHttpClient() (*http.Client, error) {
}
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsCfg,
DisableKeepAlives: true,
TLSClientConfig: tlsCfg,
},
Timeout: h.ResponseTimeout.Duration,
}
Expand Down Expand Up @@ -140,6 +141,11 @@ func (h *HTTPResponse) httpGather() (map[string]interface{}, error) {
return nil, err
}
}
defer func() {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()

fields["response_time"] = time.Since(start).Seconds()
fields["http_response_code"] = resp.StatusCode

Expand Down

0 comments on commit 17d883c

Please sign in to comment.