Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sending precalculated Content-MD5 header #1867

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11391,6 +11391,71 @@ func testPutObject0ByteV2() {
successLogger(testName, function, args, startTime).Info()
}

// Test put object with precalculated content md5.
func testPutObjectContentMD5() {
// initialize logging params
startTime := time.Now()
testName := getFuncName()
function := "PutObject(bucketName, objectName, reader, size, opts)"
opts := minio.PutObjectOptions{
SendContentMd5: false,
UserMetadata: map[string]string{
"Content-MD5": "acbd18db4cc2f85cedef654fccc4a4d8", // md5("foo")
},
}
args := map[string]interface{}{
"bucketName": "",
"objectName": "",
"size": 3,
"opts": opts,
}

// Seed random based on current time.
rand.Seed(time.Now().Unix())

// Instantiate new minio client object.
c, err := minio.New(os.Getenv(serverEndpoint),
&minio.Options{
Creds: credentials.NewStaticV2(os.Getenv(accessKey), os.Getenv(secretKey), ""),
Secure: mustParseBool(os.Getenv(enableHTTPS)),
})
if err != nil {
logError(testName, function, args, startTime, "", "MinIO client v2 object creation failed", err)
return
}

// Enable tracing, write to stderr.
// c.TraceOn(os.Stderr)

// Set user agent.
c.SetAppInfo("MinIO-go-FunctionalTest", "0.1.0")

// Generate a new random bucket name.
bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-")
args["bucketName"] = bucketName

// Make a new bucket.
err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"})
if err != nil {
logError(testName, function, args, startTime, "", "MakeBucket failed", err)
return
}

defer cleanupBucket(bucketName, c)

objectName := bucketName + "unique"
args["objectName"] = objectName

// Upload an object.
_, err = c.PutObject(context.Background(), bucketName, objectName, bytes.NewReader([]byte("foo")), 3, opts)
if err != nil {
logError(testName, function, args, startTime, "", "PutObjectContentMD5 failed", err)
return
}

successLogger(testName, function, args, startTime).Info()
}

// Test expected error cases
func testComposeObjectErrorCases() {
// initialize logging params
Expand Down Expand Up @@ -12906,6 +12971,7 @@ func main() {
testPutObjectWithChecksums()
testPutMultipartObjectWithChecksums()
testPutObject0ByteV2()
testPutObjectContentMD5()
testPutObjectNoLengthV2()
testPutObjectsUnknownV2()
testGetObjectContextV2()
Expand Down
1 change: 1 addition & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ var supportedHeaders = map[string]bool{
"content-encoding": true,
"content-disposition": true,
"content-language": true,
"content-md5": true,
"x-amz-website-redirect-location": true,
"x-amz-object-lock-mode": true,
"x-amz-metadata-directive": true,
Expand Down
Loading