aws / aws-sdk-go-v2

AWS SDK for the Go programming language.
https://aws.github.io/aws-sdk-go-v2/docs/
Apache License 2.0
2.68k stars 651 forks source link

Allow empty values on prefix headers #2816

Closed Madrigal closed 1 month ago

Madrigal commented 1 month ago

Related smithy-go change aws/smithy-go#544

Had an issue where calling S3 with metadata with an empty value caused SDKs to not serialize the value and not send the header. This allows headers with an empty string to be serialized.

Testing

Wrote the following test program

package main

import (
    "context"
    "log"

    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
)

func main() {
    cfg, err := config.LoadDefaultConfig(context.TODO(),
        config.WithRegion("us-west-2"),
        config.WithClientLogMode(aws.LogResponseWithBody|aws.LogRequestWithBody),
    )
    if err != nil {
        log.Fatalf("error: %v", err)
    }

    svc := s3.NewFromConfig(cfg)
    _, err = svc.PutObject(context.Background(), &s3.PutObjectInput{
        Bucket: aws.String("lmadrig-test-bucket"),
        Key:    aws.String("package.json"),
        Metadata: map[string]string{
            "key1": "value1",
            "key2": "",
        },
    })
    if err != nil {
        log.Fatalf("s3 error: %v", err)
    }

Ensure the logs contain the key2 empty header

PUT /package.json?x-id=PutObject HTTP/1.1
(...)
X-Amz-Date: 20241003T212511Z
X-Amz-Meta-Key1: value1
X-Amz-Meta-Key2:

Protocol tests will be updated at smithy-lang/smithy#2415