aws-beam / aws-codegen

Code generator for AWS clients in Erlang and Elixir.
Other
53 stars 49 forks source link

Duplicated content-type header when using S3 put_object #33

Closed jfacorro closed 4 years ago

jfacorro commented 4 years ago

Using the S3 client (Erlang or Elixir) in the following way results in a 403:

1> aws_s3:put_object(aws_client:make_client(), <<"bucket-name">>, <<"object/key">>, #{<<"ACL">> => <<"private">>, <<"ServerSideEncryption">> => <<"AES256">>, <<"ContentType">> => <<"text/plain">>}).

{error,#{<<"Error">> => #{
                %% ...
                <<"Message">> =>
                   <<"The request signature we calculated does not match the signature you provided. Check your key and si"...>>,
                %% ...
             }, ... }

This is because the request includes a duplicated content-type header as a result of providing the ContentType header parameter:

PUT
/bucket-name/object/key

content-type:text/plain
content-type:text/xml
host:s3.eu-west-1.amazonaws.com
x-amz-acl:private
x-amz-content-sha256:e3b0c
x-amz-date:20200814T125145Z
x-amz-security-token:Fwo...
x-amz-server-side-encryption:AES256

We need to make sure the header is added only if it does not already exist in the provided headers.