Skip to content

Commit

Permalink
fix: Unset Content-Encoding header when uncompressed
Browse files Browse the repository at this point in the history
Fixes: #1595
  • Loading branch information
mrueg committed Aug 23, 2024
1 parent b5361fe commit 2e4683c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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 2e4683c

Please sign in to comment.