support Content-Length
Even when a user sets the Content-Length header, the HTTP request still uses the Transfer-Encoding: chunked header and ignores the user-specified Content-Length.
When I used blackbox_exporter to send a POST request to an older lighttpd server, I encountered a 411 error.
The following patch, after simple testing, can resolve this issue and hopefully will be helpful.
prober/http.go | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git prober/http.go prober/http.go
index 864bf93..fe4c20e 100644
--- prober/http.go
+++ prober/http.go
@@ -438,6 +438,15 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
continue
}
+ if textproto.CanonicalMIMEHeaderKey(key) == "Content-Length" {
+ length, err := strconv.ParseInt(value, 10, 64)
+ if err != nil {
+ logger.Error("Error creating request", "err", err)
+ return
+ }
+ request.ContentLength = length
+ }
+
request.Header.Set(key, value)
}
HTTP request still uses the Transfer-Encoding: chunked header and ignores the user-specified Content-Length.
not sure if I understand the issue here, seems like expected behaviour.
I am reading more on it and it says following: source MDN
The Content-Length header must be omitted, and at the beginning of each chunk, a string of hex digits indicate the size of the chunk-data in octets
can you try setting Transfer-Encoding: to something else and it should respect the user-specified Content-Length.