Skip to content

Commit

Permalink
Check if content-range header is present. If true, don't compress the…
Browse files Browse the repository at this point in the history
… body.
  • Loading branch information
buechele authored Jul 16, 2024
1 parent 8a1fbc8 commit 5913964
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compression_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5913964

Please sign in to comment.