Fix issue #673: incorrect content length reporting (#674)
authorMarcelo Magallon <marcelo.magallon@gmail.com>
Sat, 29 Aug 2020 08:18:35 +0000 (02:18 -0600)
committerGitHub <noreply@github.com>
Sat, 29 Aug 2020 08:18:35 +0000 (09:18 +0100)
commitdaa62bf75457406f6b7f4338d5cf7fc63d7a1509
tree9984cc6fdd54378f0cc322db5bf0a8b74e1916c7
parent04d136fce36b2e7b3adb276b631cda1d72fb9944
Fix issue #673: incorrect content length reporting (#674)

Without regexp validations, the current code reads the response from the
server in order to figure out the number of bytes we received. With
regular expression validations, it's necessary to read the whole
response in order verify it if matches or not. In this case, since the
response is completely consumed, the current code is reporting a length
of 0.

Modify the code so that we can keep track of the content length in
either case: wrap the io.ReadCloser that corresponds to the response
body with another io.ReadCloser that keeps track of the number of bytes
read. After completely consuming the reponse, the wrapper is able to
report the total number of bytes read.

Add TestContentLength that checks the content lenght is reported
correctly.

Rework existing TestFailIfBodyMatchesRegexp to reduce repetiiton; add
expectations to avoid regressing issue 673.

Fixes #673

Signed-off-by: Marcelo E. Magallon <marcelo.magallon@grafana.com>
prober/http.go
prober/http_test.go