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()) }