From 5913964d55543c7ea965ba635fb637f79993a969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=BCchele?= Date: Tue, 16 Jul 2024 09:50:24 +0200 Subject: [PATCH] Check if content-range header is present. If true, don't compress the body. --- compression_handler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compression_handler.go b/compression_handler.go index d5e30f4..88287d6 100644 --- a/compression_handler.go +++ b/compression_handler.go @@ -74,7 +74,7 @@ func (c *CompressionHandler) Intercept(pipeline Pipeline, middlewareIndex int, r req = req.WithContext(ctx) } - if !reqOption.ShouldCompress() || req.Body == nil { + if !reqOption.ShouldCompress() || contentRangeIsPresent(req.Header) || req.Body == nil { return pipeline.Next(req, middlewareIndex) } if span != nil { @@ -129,6 +129,11 @@ func (c *CompressionHandler) Intercept(pipeline Pipeline, middlewareIndex int, r return resp, nil } +func contentRangeIsPresent(header http.Header) bool { + _, contentRangePresent := header["Content-Range"] + return contentRangePresent +} + func compressReqBody(reqBody []byte) (io.ReadCloser, int, error) { var buffer bytes.Buffer gzipWriter := gzip.NewWriter(&buffer)