From f0be77c4056ed29c7170d8f85be95d30bd88b9bd Mon Sep 17 00:00:00 2001 From: Eric K Lee Date: Tue, 21 Nov 2017 11:00:01 -0800 Subject: [PATCH] =?utf8?q?Setting=20httpConfig.Body=20at=20NewRequest=20to?= =?utf8?q?=20get=20Content-Length=20set=20impli=E2=80=A6=20(#265)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- prober/http.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/prober/http.go b/prober/http.go index 88bbb1a..0d938f8 100644 --- a/prober/http.go +++ b/prober/http.go @@ -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 { @@ -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{ -- 2.25.1