Skip to content

Commit

Permalink
Merge pull request #1596 from mrueg/fix-uncompressed-content-header
Browse files Browse the repository at this point in the history
fix: Unset Content-Encoding header when uncompressed
  • Loading branch information
ArthurSens authored Aug 23, 2024
2 parents 2254d6c + 187acd4 commit 67121dc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20.1
1.20.2
6 changes: 4 additions & 2 deletions prometheus/promhttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prometheus/promhttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 67121dc

Please sign in to comment.