mirror of
https://github.com/versity/versitygw.git
synced 2026-09-04 23:26:57 +00:00
feat: Added acceptRange field in GetBject backend function
This commit is contained in:
committed by
Ben McClelland
parent
70f5e0fac9
commit
c5de938637
@@ -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