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)