Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blob/azureblob: Do not panic if Content-Length and Content-Range are missing #3445

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions blob/azureblob/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length
}
attrs := driver.ReaderAttributes{
ContentType: to.String(blobDownloadResponse.ContentType),
Size: getSize(*blobDownloadResponse.ContentLength, to.String(blobDownloadResponse.ContentRange)),
Size: getSize(blobDownloadResponse.ContentLength, to.String(blobDownloadResponse.ContentRange)),
ModTime: *blobDownloadResponse.LastModified,
}
var body io.ReadCloser
Expand All @@ -584,11 +584,14 @@ func (b *bucket) NewRangeReader(ctx context.Context, key string, offset, length
}, nil
}

func getSize(contentLength int64, contentRange string) int64 {
func getSize(contentLength *int64, contentRange string) int64 {
var size int64
// Default size to ContentLength, but that's incorrect for partial-length reads,
// where ContentLength refers to the size of the returned Body, not the entire
// size of the blob. ContentRange has the full size.
size := contentLength
if contentLength != nil {
size = *contentLength
}
if contentRange != "" {
// Sample: bytes 10-14/27 (where 27 is the full size).
parts := strings.Split(contentRange, "/")
Expand Down
Loading