Skip to content

Commit

Permalink
Setting httpConfig.Body at NewRequest to get Content-Length set impli… (
Browse files Browse the repository at this point in the history
  • Loading branch information
megaqube authored and brian-brazil committed Nov 21, 2017
1 parent 260e080 commit f0be77c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,15 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
} else {
targetURL.Host = net.JoinHostPort(ip.String(), targetPort)
}
request, err := http.NewRequest(httpConfig.Method, targetURL.String(), nil)

var body io.Reader

// If a body is configured, add it to the request.
if httpConfig.Body != "" {
body = strings.NewReader(httpConfig.Body)
}

request, err := http.NewRequest(httpConfig.Method, targetURL.String(), body)
request.Host = origHost
request = request.WithContext(ctx)
if err != nil {
Expand All @@ -271,10 +279,6 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
request.Header.Set(key, value)
}

// If a body is configured, add it to the request.
if httpConfig.Body != "" {
request.Body = ioutil.NopCloser(strings.NewReader(httpConfig.Body))
}
level.Info(logger).Log("msg", "Making HTTP request", "url", request.URL.String(), "host", request.Host)

trace := &httptrace.ClientTrace{
Expand Down

0 comments on commit f0be77c

Please sign in to comment.