From b860ba1f99a6fea59847b6204d8eea6582cdd2be Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Fri, 17 May 2024 01:46:35 -0400 Subject: [PATCH] [s3] Tweak range handling on GetObject --- MODULE.bazel.lock | 6 +++--- services/s3/itest/s3_test.go | 2 +- services/s3/s3.go | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index de11ce7..9090c6d 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1493,7 +1493,7 @@ }, "@@gazelle~//:extensions.bzl%go_deps": { "general": { - "bzlTransitiveDigest": "LU6SX6N3JGbML1A3SCpN/Pm4Pck4gYEMf63QPuiuSq8=", + "bzlTransitiveDigest": "pNhMjG1EM5sSyyYAyKn5IjgRrvuFY8Sg/Oez1imX/hc=", "recordedFileInputs": { "@@//go.mod": "f7e3b6cab0d43a1da8732b8bba9c3889a0cf3f9905c59521b72df9ba97fe8347", "@@rules_go~//go.mod": "15454724af1504c4ce1782c2a7f423d596a1d8490125eb7c5bd9c95fea1991f0", @@ -2260,7 +2260,7 @@ }, "@@rules_go~//go:extensions.bzl%go_sdk": { "os:osx,arch:aarch64": { - "bzlTransitiveDigest": "fPPVH253PBJkIMD0kIJyCfyiZd4YjAur7UAXZVb1u2g=", + "bzlTransitiveDigest": "M8usE6Nbxsu7VKLDgLIKlgMg9DfiHfsizjGkZDNAw4w=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -2451,7 +2451,7 @@ }, "@@rules_java~//java:extensions.bzl%toolchains": { "general": { - "bzlTransitiveDigest": "tJHbmWnq7m+9eUBnUdv7jZziQ26FmcGL9C5/hU3Q9UQ=", + "bzlTransitiveDigest": "0N5b5J9fUzo0sgvH4F3kIEaeXunz4Wy2/UtSFV/eXUY=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/services/s3/itest/s3_test.go b/services/s3/itest/s3_test.go index 7455087..37f91e5 100644 --- a/services/s3/itest/s3_test.go +++ b/services/s3/itest/s3_test.go @@ -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"}, diff --git a/services/s3/s3.go b/services/s3/s3.go index 0127194..c60cea0 100644 --- a/services/s3/s3.go +++ b/services/s3/s3.go @@ -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. @@ -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" {