diff --git a/go.mod b/go.mod index db64fdc2..db22c082 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/influxdata/influxdb-observability/otel2influx v0.2.19 github.com/influxdata/influxql v1.1.1-0.20211004132434-7e7d61973256 github.com/json-iterator/go v1.1.12 - github.com/klauspost/compress v1.17.11 + github.com/klauspost/compress v1.17.2 github.com/mattn/go-sqlite3 v1.14.19 github.com/mitchellh/cli v1.1.5 github.com/nxadm/tail v1.4.11 diff --git a/go.sum b/go.sum index 8602ad28..49adee1a 100644 --- a/go.sum +++ b/go.sum @@ -1177,8 +1177,8 @@ github.com/klauspost/compress v1.11.13/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdY github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= -github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4= +github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= diff --git a/lib/util/lifted/influx/httpd/handler_compress.go b/lib/util/lifted/influx/httpd/handler_compress.go index 64ea07ca..3766aadc 100644 --- a/lib/util/lifted/influx/httpd/handler_compress.go +++ b/lib/util/lifted/influx/httpd/handler_compress.go @@ -1,3 +1,17 @@ +// Copyright 2024 Huawei Cloud Computing Technologies Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package httpd import ( @@ -23,18 +37,19 @@ type lazyCompressResponseWriter struct { func compressFilter(inner http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var writer io.Writer = w - - if shouldApplyGzip(r) { + contentEncoding := r.Header.Get("Content-Encoding") + switch { + case strings.Contains(contentEncoding, "gzip"): gz := getGzipWriter(w) defer gz.Close() writer = gz w.Header().Set("Content-Encoding", "gzip") - } else if shouldApplyZstd(r) { + case strings.Contains(contentEncoding, "zstd"): enc := getZstdWriter(w) defer enc.Close() writer = enc w.Header().Set("Content-Encoding", "zstd") - } else { + default: inner.ServeHTTP(w, r) return } @@ -55,14 +70,6 @@ func compressFilter(inner http.Handler) http.Handler { }) } -func shouldApplyGzip(r *http.Request) bool { - return strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") -} - -func shouldApplyZstd(r *http.Request) bool { - return strings.Contains(r.Header.Get("Accept-Encoding"), "zstd") -} - func (w *lazyCompressResponseWriter) WriteHeader(code int) { if !w.wroteHeader { w.ResponseWriter.Header().Del("Content-Length")