How to enable setting the request headers for Get and Delete in Amazon SDK for .NET

From the source code, modify the below files:

AWSSDK_DotNet35\Amazon.S3\Model\Internal\MarshallTransformations\GetObjectRequestMarshaller.cs

AWSSDK_DotNet35\Amazon.S3\Model\Internal\MarshallTransformations\DeleteObjectRequestMarshaller.cs

Modify the public IRequest Marshall(<parameter>) method by adding the below statements:

var headers = <requestObject>.Headers;
foreach (var key in headers.Keys)
      request.Headers[key] = headers[key];

You will need to add the property for the headers to the classes (directly - not in their base classes):

private HeadersCollection headersCollection = new HeadersCollection();

/// <summary>
        /// The collection of headers for the request.
        /// </summary>
        public HeadersCollection Headers
        {
            get
            {
                if (this.headersCollection == null)
                    this.headersCollection = new HeadersCollection();
                return this.headersCollection;
            }
            internal set
            {
                this.headersCollection = value;
            }
        }

In your client code, you can then pass the headers:

string time = AWSSDKUtils.GetFormattedTimestampRFC822(TemporaryAmazonTokenHandler.GetTimeCorrectionMinutes());
                            request.Headers[HeaderKeys.DateHeader] = time;
                            request.Headers[HeaderKeys.XAmzDateHeader] = time;

For the entire scheme to work, you need to write additional code which makes sure that these header values are actually applied to the web request as described below:

http://deepinsightsdotnet.blogspot.com/2014/12/is-there-anyway-to-programmatically.html

Comments

Popular posts from this blog

Tutorial: Using Google Cloud Storage from C# and .NET

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?

The ridiculous interview experience