Skip to content

Commit

Permalink
Check if content-range is a bytes range
Browse files Browse the repository at this point in the history
  • Loading branch information
buechele authored Jul 16, 2024
1 parent e2aac71 commit 9b6c5cf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions 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() || contentRangeIsPresent(req.Header) || req.Body == nil {
if !reqOption.ShouldCompress() || contentRangeBytesIsPresent(req.Header) || req.Body == nil {
return pipeline.Next(req, middlewareIndex)
}
if span != nil {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9b6c5cf

Please sign in to comment.