Aws-sdk-net: Can't set CacheControl header on S3 object when use AmazonS3Client.PutObject

Created on 24 Sep 2019  路  2Comments  路  Source: aws/aws-sdk-net

I tied to put object on S3 with CacheControl header has ',' character and got "The request signature we calculated does not match the signature you provided" exception.

Expected Behavior

It should be possible to put object on s3 with header CacheControl = "max-age=3600,s-maxage=60"

Current Behavior

If user puts value with "," character (for example: max-age=7200,s-maxage=60) to PutObjectRequest.Headers.CacheControl, unhandled exception appears:
Amazon.S3.AmazonS3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method

Steps to Reproduce (for bugs)

Here is my sample:
```c#
var s3 = new AmazonS3Client();
var request = new PutObjectRequest {
BucketName = "my-bucket",
Key = "my-object.txt",
CannedACL = S3CannedACL.PublicRead,
ContentBody = "my body",
Headers = {
CacheControl = "max-age=7200,s-maxage=60"
}
};
s3.PutObjectAsync(request).GetAwaiter().GetResult();

## Context
I have S3 bucket. On the top of this bucket I have CloudFront and I want to control cloudfront cache behavior with a help of two http headers **max-age** and  **s-maxage**

## Your Environment
* AWSSDK.S3 version used: 3.3.104.31
* Operating System and version: Windows 10
* Visual Studio version: 2017
* Targeted .NET platform: netcoreapp2.1

## .NET Core Info
* Output of `dotnet --info`: 

.NET Core SDK (reflecting any global.json):
Version: 2.2.104
Commit: 73f036d4ac

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.104\

Host (useful for support):
Version: 2.2.2
Commit: a4fd7b2c84

.NET Core SDKs installed:
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.509 [C:\Program Files\dotnet\sdk]
2.2.104 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

* Contents of project.json/project.csproj: 
```xml
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AWSSDK.S3" Version="3.3.104.31" />
  </ItemGroup>
</Project>

B bug moduls3

Most helpful comment

Hi @vachumakov, this appears to be the same issue as https://github.com/aws/aws-sdk-net/issues/823. I was able to reproduce your problem, and then I got it to work by adding the suggested space after the comma. We'll take another look at this problem so users don't have to worry about the space.

All 2 comments

Hi @vachumakov, this appears to be the same issue as https://github.com/aws/aws-sdk-net/issues/823. I was able to reproduce your problem, and then I got it to work by adding the suggested space after the comma. We'll take another look at this problem so users don't have to worry about the space.

Thanks @klaytaybai Handling the spaces issue on the AWS SDK side would be very helpful.

Was this page helpful?
0 / 5 - 0 ratings