Skip to content

Commit

Permalink
Merge pull request #8 from dzbarsky/fix_s3e
Browse files Browse the repository at this point in the history
[s3] Tweak range handling on GetObject
  • Loading branch information
DavidZbarsky-at authored May 17, 2024
2 parents 095928d + b860ba1 commit 735ad13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/s3/itest/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func TestRangeQuery(t *testing.T) {
}

testCases := []RangeTestCase{
{Name: "entire range", Range: "bytes=0-28", Body: "hello world hi things are fun"},
{Name: "entire range", Range: "bytes=0-28", Body: "hello world hi things are fun", ContentRange: "bytes 0-28/29"},
{Name: "Skip entire first part and half of second part", Range: "bytes=8-13", Body: "rld hi", ContentRange: "bytes 8-13/29"},
{Name: "Prefix", Range: "bytes=0-8", Body: "hello wor", ContentRange: "bytes 0-8/29"},
{Name: "Suffix", Range: "bytes=-4", Body: " fun", ContentRange: "bytes 25-28/29"},
Expand Down
14 changes: 7 additions & 7 deletions services/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (s *S3) getObject(input GetObjectInput, includeBody bool) (*GetObjectOutput
}
output.Body = io.MultiReader(readers...)
output.ContentLength = totalLength
if totalLength < object.ContentLength {
if len(ranges) > 0 {
output.HttpStatus = http.StatusPartialContent
if len(ranges) == 1 {
// Content-Range is inclusive on the end, where ranges[0].endByte is exclusive. We subtract one to convert.
Expand Down Expand Up @@ -475,23 +475,23 @@ func (s *S3) CopyObject(input CopyObjectInput) (*CopyObjectOutput, *awserrors.Er
s.mu.Lock()
defer s.mu.Unlock()

// "/bucket/path/to/key"
// "bucket/path/to/key"
copySource, err := url.PathUnescape(input.CopySource)
if err != nil {
return nil, awserrors.XXX_TODO(err.Error())
}
parts := strings.SplitN(copySource, "/", 3)
sourceBucket := parts[1]
sourceKey := parts[2]
parts := strings.SplitN(copySource, "/", 2)
sourceBucket := parts[0]
sourceKey := parts[1]

b, ok := s.buckets[sourceBucket]
if !ok {
return nil, awserrors.XXX_TODO("no bucket")
return nil, awserrors.XXX_TODO("no bucket: " + sourceBucket)
}

object, ok := b.objects[sourceKey]
if !ok {
return nil, awserrors.XXX_TODO("no source item")
return nil, awserrors.XXX_TODO("no source item: " + sourceKey)
}

if input.MetadataDirective == "REPLACE" {
Expand Down

0 comments on commit 735ad13

Please sign in to comment.