diff --git a/backend/common.go b/backend/common.go index 03cc34d..aa11d14 100644 --- a/backend/common.go +++ b/backend/common.go @@ -56,7 +56,7 @@ func GetTimePtr(t time.Time) *time.Time { } var ( - errInvalidRange = s3err.GetAPIError(s3err.ErrInvalidRequest) + errInvalidRange = s3err.GetAPIError(s3err.ErrInvalidRange) ) // ParseRange parses input range header and returns startoffset, length, and diff --git a/integration/tests.go b/integration/tests.go index 7780eb2..16cd71a 100644 --- a/integration/tests.go +++ b/integration/tests.go @@ -1031,6 +1031,20 @@ func TestRangeGet(s *S3Conf) { return } + // Invalid range + invRange := "bytes=100-asd" + ctx, cancel = context.WithTimeout(context.Background(), shortTimeout) + _, err = s3client.GetObject(ctx, &s3.GetObjectInput{ + Bucket: &bucket, + Key: &name, + Range: &invRange, + }) + defer cancel() + if err == nil { + failF("%v: expected range error", testname) + return + } + rangeString := "bytes=100-200" ctx, cancel = context.WithTimeout(context.Background(), shortTimeout) diff --git a/s3err/s3err.go b/s3err/s3err.go index 5da58a6..f445d2f 100644 --- a/s3err/s3err.go +++ b/s3err/s3err.go @@ -106,7 +106,9 @@ const ( ErrNotImplemented ErrPreconditionFailed ErrInvalidObjectState + ErrInvalidRange + // Non-AWS errors ErrExistingObjectIsDirectory ErrObjectParentIsFile ) @@ -374,6 +376,11 @@ var errorCodeResponse = map[ErrorCode]APIError{ Description: "The operation is not valid for the current state of the object", HTTPStatusCode: http.StatusForbidden, }, + ErrInvalidRange: { + Code: "InvalidRange", + Description: "The requested range is not valid for the request. Try another range.", + HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable, + }, ErrExistingObjectIsDirectory: { Code: "ExistingObjectIsDirectory", Description: "Existing Object is a directory.",