Skip to content

Commit

Permalink
Support sending precalculated Content-MD5 header
Browse files Browse the repository at this point in the history
We already have the MD5 of the content and want to send along the Content-MD5 header without minio-go having to recalculate the hash. With this PR we can set `SendContentMd5: false` and send our hash as `UserMetadata`.

Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Aug 7, 2023
1 parent c0ea248 commit 6195b80
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions functional_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11391,6 +11391,70 @@ 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)"
args := map[string]interface{}{
"bucketName": "",
"objectName": "",
"size": 3,
"opts": minio.PutObjectOptions{
SendContentMd5: false,
UserMetadata: map[string]string{
"Content-MD5": "acbd18db4cc2f85cedef654fccc4a4d8", // md5("foo")
},
}

Check failure on line 11409 in functional_tests.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and ubuntu-latest

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 11409 in functional_tests.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.19.x and windows-latest

syntax error: unexpected newline in composite literal; possibly missing comma or }
}

// 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, args["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
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

0 comments on commit 6195b80

Please sign in to comment.