Fix segmentation violation on connection failed (#7593)
This commit is contained in:
@@ -271,14 +271,6 @@ func (h *HTTPResponse) httpGather(u string) (map[string]interface{}, map[string]
|
||||
resp, err := h.client.Do(request)
|
||||
response_time := time.Since(start).Seconds()
|
||||
|
||||
// Add the response headers
|
||||
for headerName, tag := range h.HTTPHeaderTags {
|
||||
headerValues, foundHeader := resp.Header[headerName]
|
||||
if foundHeader && len(headerValues) > 0 {
|
||||
tags[tag] = headerValues[0]
|
||||
}
|
||||
}
|
||||
|
||||
// If an error in returned, it means we are dealing with a network error, as
|
||||
// HTTP error codes do not generate errors in the net/http library
|
||||
if err != nil {
|
||||
@@ -306,6 +298,14 @@ func (h *HTTPResponse) httpGather(u string) (map[string]interface{}, map[string]
|
||||
// required by the net/http library
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Add the response headers
|
||||
for headerName, tag := range h.HTTPHeaderTags {
|
||||
headerValues, foundHeader := resp.Header[headerName]
|
||||
if foundHeader && len(headerValues) > 0 {
|
||||
tags[tag] = headerValues[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Set log the HTTP response code
|
||||
tags["status_code"] = strconv.Itoa(resp.StatusCode)
|
||||
fields["http_response_code"] = resp.StatusCode
|
||||
|
||||
Reference in New Issue
Block a user