From f7f8f3a1e2c09da4b88b78b7e04a9252187cf71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 23 Aug 2024 15:04:34 +0200 Subject: [PATCH 1/2] fix: Unset Content-Encoding header when uncompressed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #1595 Signed-off-by: Manuel Rüger --- prometheus/promhttp/http.go | 6 ++++-- prometheus/promhttp/http_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/prometheus/promhttp/http.go b/prometheus/promhttp/http.go index 2e0b9a8..e598e66 100644 --- a/prometheus/promhttp/http.go +++ b/prometheus/promhttp/http.go @@ -203,8 +203,10 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO defer closeWriter() - rsp.Header().Set(contentEncodingHeader, encodingHeader) - + // Set Content-Encoding only when data is compressed + if encodingHeader != string(Identity) { + rsp.Header().Set(contentEncodingHeader, encodingHeader) + } enc := expfmt.NewEncoder(w, contentType) // handleError handles the error according to opts.ErrorHandling diff --git a/prometheus/promhttp/http_test.go b/prometheus/promhttp/http_test.go index 0ed8fe3..3ad2d1d 100644 --- a/prometheus/promhttp/http_test.go +++ b/prometheus/promhttp/http_test.go @@ -267,7 +267,7 @@ func TestInstrumentMetricHandler(t *testing.T) { t.Errorf("got HTTP status code %d, want %d", got, want) } - if got, want := writer.Header().Get(contentEncodingHeader), string(Identity); got != want { + if got, want := writer.Header().Get(contentEncodingHeader), ""; got != want { t.Errorf("got HTTP content encoding header %s, want %s", got, want) } From 187acd4ca1a05e3207990e427cae7057a1e58961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 23 Aug 2024 18:55:43 +0200 Subject: [PATCH 2/2] Cut 1.20.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Rüger --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37749eb..f83a027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +## 1.20.2 / 2024-08-23 + +* [BUGFIX] promhttp: Unset Content-Encoding header when data is uncompressed. #1596 + ## 1.20.1 / 2024-08-20 * [BUGFIX] process-collector: Fixed unregistered descriptor error when using process collector with `PedanticRegistry` on linux machines. #1587 diff --git a/VERSION b/VERSION index 0044d6c..769e37e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.20.1 +1.20.2