Created
November 7, 2012 23:39
-
-
Save blowdart/4035399 to your computer and use it in GitHub Desktop.
Hello request in flight body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) | |
{ | |
if (request.Headers.Date == null) | |
{ | |
request.Headers.Date = DateTime.UtcNow; | |
} | |
// Check if we have request content, if we do then we need to add a Content-MD5 header. | |
if (request.Content != null && request.Content.Headers.ContentMD5 == null) | |
{ | |
await request.Content.LoadIntoBufferAsync().ConfigureAwait(false); | |
using (var bodyStream = new MemoryStream()) | |
{ | |
await request.Content.CopyToAsync(bodyStream).ConfigureAwait(false); | |
bodyStream.Position = 0; | |
using (var md5 = new MD5CryptoServiceProvider()) | |
{ | |
request.Content.Headers.ContentMD5 = md5.ComputeHash(bodyStream); | |
} | |
} | |
} | |
byte[] hash = SharedKeySignature.Calculate(request, this.accountName, this.sharedSecret); | |
request.Headers.Authorization = new AuthenticationHeaderValue( | |
SharedKeyAuthentication.Scheme, | |
string.Format(CultureInfo.InvariantCulture, "{0}:{1}", this.accountName, Convert.ToBase64String(hash))); | |
// And finally hand off the request to the InnerHandler. | |
return await base.SendAsync(request, cancellationToken); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment