From d2f0f54d68bb3463339a29179ee794acbe3d4cf2 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Mon, 26 Nov 2018 13:05:07 +0000 Subject: [PATCH] Pass through content-type for non-compressed output. (#4912) Fixes #4911 Signed-off-by: Brian Brazil --- scrape/scrape.go | 5 ++++- scrape/scrape_test.go | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scrape/scrape.go b/scrape/scrape.go index 382d2533c..1eeb447ce 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -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 { diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index 3d6afdbb9..29cad0527 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -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()) }