Skip to content

Commit 67121dc

Browse files
authored
Merge pull request #1596 from mrueg/fix-uncompressed-content-header
fix: Unset Content-Encoding header when uncompressed
2 parents 2254d6c + 187acd4 commit 67121dc

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
## 1.20.2 / 2024-08-23
4+
5+
* [BUGFIX] promhttp: Unset Content-Encoding header when data is uncompressed. #1596
6+
37
## 1.20.1 / 2024-08-20
48

59
* [BUGFIX] process-collector: Fixed unregistered descriptor error when using process collector with `PedanticRegistry` on linux machines. #1587

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.20.1
1+
1.20.2

prometheus/promhttp/http.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,10 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
203203

204204
defer closeWriter()
205205

206-
rsp.Header().Set(contentEncodingHeader, encodingHeader)
207-
206+
// Set Content-Encoding only when data is compressed
207+
if encodingHeader != string(Identity) {
208+
rsp.Header().Set(contentEncodingHeader, encodingHeader)
209+
}
208210
enc := expfmt.NewEncoder(w, contentType)
209211

210212
// handleError handles the error according to opts.ErrorHandling

prometheus/promhttp/http_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestInstrumentMetricHandler(t *testing.T) {
267267
t.Errorf("got HTTP status code %d, want %d", got, want)
268268
}
269269

270-
if got, want := writer.Header().Get(contentEncodingHeader), string(Identity); got != want {
270+
if got, want := writer.Header().Get(contentEncodingHeader), ""; got != want {
271271
t.Errorf("got HTTP content encoding header %s, want %s", got, want)
272272
}
273273

0 commit comments

Comments
 (0)