Skip to content

Commit

Permalink
docker: support for requesting chunks without end offset
Browse files Browse the repository at this point in the history
if the specified length for the range is set to -1, then request all
the data possible by using the "Range: <unit>=<range-start>-" syntax
for the HTTP range.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed May 2, 2024
1 parent 7e861b5 commit 679afe4
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docker/docker_image_src.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"math"
"mime"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -342,8 +343,18 @@ func (s *dockerImageSource) GetBlobAt(ctx context.Context, info types.BlobInfo,
headers := make(map[string][]string)

rangeVals := make([]string, 0, len(chunks))
lastFound := false
for _, c := range chunks {
rangeVals = append(rangeVals, fmt.Sprintf("%d-%d", c.Offset, c.Offset+c.Length-1))
if lastFound {
return nil, nil, fmt.Errorf("invalid chunk requested: %v", c)
}
// If the Length is set to -1, then request anything after the specified offset.
if c.Length == math.MaxUint64 {
lastFound = true
rangeVals = append(rangeVals, fmt.Sprintf("%d-", c.Offset))
} else {
rangeVals = append(rangeVals, fmt.Sprintf("%d-%d", c.Offset, c.Offset+c.Length-1))
}
}

headers["Range"] = []string{fmt.Sprintf("bytes=%s", strings.Join(rangeVals, ","))}
Expand Down

0 comments on commit 679afe4

Please sign in to comment.