mirror of
https://github.com/versity/versitygw.git
synced 2026-01-04 02:53:55 +00:00
feat: Added acceptRange field in GetBject backend function
This commit is contained in:
committed by
Ben McClelland
parent
70f5e0fac9
commit
c5de938637
@@ -32,7 +32,7 @@ type Backend interface {
|
||||
|
||||
PutObject(*s3.PutObjectInput) (string, error)
|
||||
HeadObject(bucket, object string, etag string) (*s3.HeadObjectOutput, error)
|
||||
GetObject(bucket, object string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
GetObject(bucket, object, acceptRange string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
GetObjectAcl(bucket, object string) (*s3.GetObjectAclOutput, error)
|
||||
GetObjectAttributes(bucket, object string, attributes []string) (*s3.GetObjectAttributesOutput, error)
|
||||
CopyObject(srcBucket, srcObject, DstBucket, dstObject string) (*s3.CopyObjectOutput, error)
|
||||
@@ -129,7 +129,7 @@ func (BackendUnsupported) DeleteObject(bucket, object string) error {
|
||||
func (BackendUnsupported) DeleteObjects(bucket string, objects *s3.DeleteObjectsInput) error {
|
||||
return s3err.GetAPIError(s3err.ErrNotImplemented)
|
||||
}
|
||||
func (BackendUnsupported) GetObject(bucket, object string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
func (BackendUnsupported) GetObject(bucket, object, acceptRange string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
return nil, s3err.GetAPIError(s3err.ErrNotImplemented)
|
||||
}
|
||||
func (BackendUnsupported) HeadObject(bucket, object string, etag string) (*s3.HeadObjectOutput, error) {
|
||||
|
||||
@@ -50,7 +50,7 @@ var _ Backend = &BackendMock{}
|
||||
// GetIAMConfigFunc: func() ([]byte, error) {
|
||||
// panic("mock out the GetIAMConfig method")
|
||||
// },
|
||||
// GetObjectFunc: func(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
// GetObjectFunc: func(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
// panic("mock out the GetObject method")
|
||||
// },
|
||||
// GetObjectAclFunc: func(bucket string, object string) (*s3.GetObjectAclOutput, error) {
|
||||
@@ -160,7 +160,7 @@ type BackendMock struct {
|
||||
GetIAMConfigFunc func() ([]byte, error)
|
||||
|
||||
// GetObjectFunc mocks the GetObject method.
|
||||
GetObjectFunc func(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
GetObjectFunc func(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
|
||||
// GetObjectAclFunc mocks the GetObjectAcl method.
|
||||
GetObjectAclFunc func(bucket string, object string) (*s3.GetObjectAclOutput, error)
|
||||
@@ -313,6 +313,8 @@ type BackendMock struct {
|
||||
Bucket string
|
||||
// Object is the object argument value.
|
||||
Object string
|
||||
// AcceptRange is the acceptRange argument value.
|
||||
AcceptRange string
|
||||
// StartOffset is the startOffset argument value.
|
||||
StartOffset int64
|
||||
// Length is the length argument value.
|
||||
@@ -894,19 +896,21 @@ func (mock *BackendMock) GetIAMConfigCalls() []struct {
|
||||
}
|
||||
|
||||
// GetObject calls GetObjectFunc.
|
||||
func (mock *BackendMock) GetObject(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
func (mock *BackendMock) GetObject(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
if mock.GetObjectFunc == nil {
|
||||
panic("BackendMock.GetObjectFunc: method is nil but Backend.GetObject was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
}{
|
||||
Bucket: bucket,
|
||||
Object: object,
|
||||
AcceptRange: acceptRange,
|
||||
StartOffset: startOffset,
|
||||
Length: length,
|
||||
Writer: writer,
|
||||
@@ -914,7 +918,7 @@ func (mock *BackendMock) GetObject(bucket string, object string, startOffset int
|
||||
mock.lockGetObject.Lock()
|
||||
mock.calls.GetObject = append(mock.calls.GetObject, callInfo)
|
||||
mock.lockGetObject.Unlock()
|
||||
return mock.GetObjectFunc(bucket, object, startOffset, length, writer)
|
||||
return mock.GetObjectFunc(bucket, object, acceptRange, startOffset, length, writer)
|
||||
}
|
||||
|
||||
// GetObjectCalls gets all the calls that were made to GetObject.
|
||||
@@ -924,6 +928,7 @@ func (mock *BackendMock) GetObject(bucket string, object string, startOffset int
|
||||
func (mock *BackendMock) GetObjectCalls() []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
@@ -931,6 +936,7 @@ func (mock *BackendMock) GetObjectCalls() []struct {
|
||||
var calls []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
|
||||
@@ -822,7 +822,7 @@ func (p *Posix) DeleteObjects(bucket string, objects *s3.DeleteObjectsInput) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Posix) GetObject(bucket, object string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
func (p *Posix) GetObject(bucket, object, acceptRange string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
_, err := os.Stat(bucket)
|
||||
if err != nil && os.IsNotExist(err) {
|
||||
return nil, s3err.GetAPIError(s3err.ErrNoSuchBucket)
|
||||
@@ -867,6 +867,7 @@ func (p *Posix) GetObject(bucket, object string, startOffset, length int64, writ
|
||||
// TODO: fill range request header?
|
||||
// TODO: parse tags for tag count?
|
||||
return &s3.GetObjectOutput{
|
||||
AcceptRanges: &acceptRange,
|
||||
ContentLength: length,
|
||||
ContentEncoding: &contentEncoding,
|
||||
ContentType: &contentType,
|
||||
|
||||
@@ -51,7 +51,7 @@ var _ backend.Backend = &BackendMock{}
|
||||
// GetIAMConfigFunc: func() ([]byte, error) {
|
||||
// panic("mock out the GetIAMConfig method")
|
||||
// },
|
||||
// GetObjectFunc: func(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
// GetObjectFunc: func(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
// panic("mock out the GetObject method")
|
||||
// },
|
||||
// GetObjectAclFunc: func(bucket string, object string) (*s3.GetObjectAclOutput, error) {
|
||||
@@ -161,7 +161,7 @@ type BackendMock struct {
|
||||
GetIAMConfigFunc func() ([]byte, error)
|
||||
|
||||
// GetObjectFunc mocks the GetObject method.
|
||||
GetObjectFunc func(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
GetObjectFunc func(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error)
|
||||
|
||||
// GetObjectAclFunc mocks the GetObjectAcl method.
|
||||
GetObjectAclFunc func(bucket string, object string) (*s3.GetObjectAclOutput, error)
|
||||
@@ -314,6 +314,8 @@ type BackendMock struct {
|
||||
Bucket string
|
||||
// Object is the object argument value.
|
||||
Object string
|
||||
// AcceptRange is the acceptRange argument value.
|
||||
AcceptRange string
|
||||
// StartOffset is the startOffset argument value.
|
||||
StartOffset int64
|
||||
// Length is the length argument value.
|
||||
@@ -895,19 +897,21 @@ func (mock *BackendMock) GetIAMConfigCalls() []struct {
|
||||
}
|
||||
|
||||
// GetObject calls GetObjectFunc.
|
||||
func (mock *BackendMock) GetObject(bucket string, object string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
func (mock *BackendMock) GetObject(bucket string, object string, acceptRange string, startOffset int64, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
if mock.GetObjectFunc == nil {
|
||||
panic("BackendMock.GetObjectFunc: method is nil but Backend.GetObject was just called")
|
||||
}
|
||||
callInfo := struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
}{
|
||||
Bucket: bucket,
|
||||
Object: object,
|
||||
AcceptRange: acceptRange,
|
||||
StartOffset: startOffset,
|
||||
Length: length,
|
||||
Writer: writer,
|
||||
@@ -915,7 +919,7 @@ func (mock *BackendMock) GetObject(bucket string, object string, startOffset int
|
||||
mock.lockGetObject.Lock()
|
||||
mock.calls.GetObject = append(mock.calls.GetObject, callInfo)
|
||||
mock.lockGetObject.Unlock()
|
||||
return mock.GetObjectFunc(bucket, object, startOffset, length, writer)
|
||||
return mock.GetObjectFunc(bucket, object, acceptRange, startOffset, length, writer)
|
||||
}
|
||||
|
||||
// GetObjectCalls gets all the calls that were made to GetObject.
|
||||
@@ -925,6 +929,7 @@ func (mock *BackendMock) GetObject(bucket string, object string, startOffset int
|
||||
func (mock *BackendMock) GetObjectCalls() []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
@@ -932,6 +937,7 @@ func (mock *BackendMock) GetObjectCalls() []struct {
|
||||
var calls []struct {
|
||||
Bucket string
|
||||
Object string
|
||||
AcceptRange string
|
||||
StartOffset int64
|
||||
Length int64
|
||||
Writer io.Writer
|
||||
|
||||
@@ -62,7 +62,9 @@ func (c S3ApiController) GetActions(ctx *fiber.Ctx) error {
|
||||
return responce(ctx, res, err)
|
||||
}
|
||||
|
||||
bRangeSl := strings.Split(ctx.Get("Range"), "=")
|
||||
acceptRange := ctx.Get("Range")
|
||||
|
||||
bRangeSl := strings.Split(acceptRange, "=")
|
||||
if len(bRangeSl) < 2 {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
@@ -82,7 +84,7 @@ func (c S3ApiController) GetActions(ctx *fiber.Ctx) error {
|
||||
return errors.New("wrong api call")
|
||||
}
|
||||
|
||||
res, err := c.be.GetObject(bucket, key, int64(startOffset), int64(length), ctx.Response().BodyWriter())
|
||||
res, err := c.be.GetObject(bucket, key, acceptRange, int64(startOffset), int64(length), ctx.Response().BodyWriter())
|
||||
return responce(ctx, res, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ func TestS3ApiController_GetActions(t *testing.T) {
|
||||
GetObjectAttributesFunc: func(bucket, object string, attributes []string) (*s3.GetObjectAttributesOutput, error) {
|
||||
return &s3.GetObjectAttributesOutput{}, nil
|
||||
},
|
||||
GetObjectFunc: func(bucket, object string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
GetObjectFunc: func(bucket, object, acceptRange string, startOffset, length int64, writer io.Writer) (*s3.GetObjectOutput, error) {
|
||||
return &s3.GetObjectOutput{Metadata: nil}, nil
|
||||
},
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user