From 9b6c5cf2d6abaa0c23eae8d06b4c811fea0016f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=BCchele?= Date: Tue, 16 Jul 2024 12:55:23 +0200 Subject: [PATCH] Check if content-range is a bytes range --- compression_handler.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compression_handler.go b/compression_handler.go index 62d84e6..3ef82d5 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() || contentRangeIsPresent(req.Header) || req.Body == nil { + if !reqOption.ShouldCompress() || contentRangeBytesIsPresent(req.Header) || req.Body == nil { return pipeline.Next(req, middlewareIndex) } if span != nil { @@ -129,9 +129,14 @@ 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 contentRangeBytesIsPresent(header http.Header) bool { + contentRanges, _ := header["Content-Range"] + for _, contentRange := range contentRanges { + if strings.Contains(strings.ToLower(contentRange), "bytes") { + return true + } + } + return false } func compressReqBody(reqBody []byte) (io.ReadCloser, int, error) {