Pass through content-type for non-compressed output. (#4912)

Fixes #4911

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
Brian Brazil 2018-11-26 13:05:07 +00:00 committed by GitHub
parent bea302e061
commit d2f0f54d68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -480,7 +480,10 @@ func (s *targetScraper) scrape(ctx context.Context, w io.Writer) (string, error)
if resp.Header.Get("Content-Encoding") != "gzip" {
_, err = io.Copy(w, resp.Body)
return "", err
if err != nil {
return "", err
}
return resp.Header.Get("Content-Type"), nil
}
if s.gzipr == nil {

View file

@ -1212,9 +1212,11 @@ func TestTargetScraperScrapeOK(t *testing.T) {
}
var buf bytes.Buffer
if _, err := ts.scrape(context.Background(), &buf); err != nil {
contentType, err := ts.scrape(context.Background(), &buf)
if err != nil {
t.Fatalf("Unexpected scrape error: %s", err)
}
require.Equal(t, "text/plain; version=0.0.4", contentType)
require.Equal(t, "metric_a 1\nmetric_b 2\n", buf.String())
}