mirror of
https://github.com/versity/versitygw.git
synced 2026-09-26 01:44:49 +00:00
feat: adds x-amz-object-size in PutObject response headers
Closes #1518 Adds the `x-amz-object-size` header to the `PutObject` response, indicating the size of the uploaded object. This change is applied to the POSIX, Azure, and S3 proxy backends.
This commit is contained in:
@@ -3418,10 +3418,33 @@ func PutObject_racey_success(s *S3Conf) error {
|
||||
func PutObject_success(s *S3Conf) error {
|
||||
testName := "PutObject_success"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
_, err := putObjects(s3client, []string{"my-obj"}, bucket)
|
||||
lgth := int64(100)
|
||||
res, err := putObjectWithData(lgth, &s3.PutObjectInput{
|
||||
Bucket: &bucket,
|
||||
Key: getPtr("my-obj"),
|
||||
}, s3client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// skip the ETag check for azure tests
|
||||
if !s.azureTests {
|
||||
etag, err := calculateEtag(res.data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if getString(res.res.ETag) != etag {
|
||||
return fmt.Errorf("expected ETag to be %s, intead got %s", getString(res.res.ETag), etag)
|
||||
}
|
||||
}
|
||||
if res.res.Size == nil {
|
||||
return fmt.Errorf("unexpected nil object Size")
|
||||
}
|
||||
if *res.res.Size != lgth {
|
||||
return fmt.Errorf("expected the object size to be %v, instead got %v", lgth, *res.res.Size)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
@@ -1798,3 +1799,13 @@ func testOPTIONSEdnpoint(s *S3Conf, bucket, origin, method string, headers strin
|
||||
|
||||
return comparePreflightResult(expected, result)
|
||||
}
|
||||
|
||||
func calculateEtag(data []byte) (string, error) {
|
||||
h := md5.New()
|
||||
_, err := h.Write(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dataSum := h.Sum(nil)
|
||||
return fmt.Sprintf("\"%s\"", hex.EncodeToString(dataSum[:])), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user