fix: Unset Content-Encoding header when uncompressed

Fixes: #1595
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
Manuel Rüger 2024-08-23 15:04:34 +02:00
parent 2254d6c308
commit f7f8f3a1e2
2 changed files with 5 additions and 3 deletions

View File

@ -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

View File

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