Created
June 1, 2013 21:32
-
-
Save daanl/5691791 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public string GetCanonicalizedHeaders(HttpWebRequest request) | |
{ | |
ArrayList headerNameList = new ArrayList(); | |
StringBuilder sb = new StringBuilder(); | |
foreach (string headerName in request.Headers.Keys) | |
{ | |
if (headerName.ToLowerInvariant().StartsWith("x-ms-", StringComparison.Ordinal)) | |
{ | |
headerNameList.Add(headerName.ToLowerInvariant()); | |
} | |
} | |
headerNameList.Sort(); | |
foreach (string headerName in headerNameList) | |
{ | |
StringBuilder builder = new StringBuilder(headerName); | |
string separator = ":"; | |
foreach (string headerValue in GetHeaderValues(request.Headers, headerName)) | |
{ | |
string trimmedValue = headerValue.Replace("\r\n", String.Empty); | |
builder.Append(separator); | |
builder.Append(trimmedValue); | |
separator = ","; | |
} | |
sb.Append(builder.ToString()); | |
sb.Append("\n"); | |
} | |
return sb.ToString(); | |
} |
This file contains hidden or 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
private string GetCanonicalizedHeaders(HttpClient httpClient) | |
{ | |
var stringBuilder = new StringBuilder(); | |
foreach (var header in httpClient.DefaultRequestHeaders | |
.Where(x => x.Key.StartsWith("x-ms-", StringComparison.InvariantCultureIgnoreCase)) | |
.OrderBy(x => x.Key) | |
) | |
{ | |
var builder = new StringBuilder(header.Key); | |
var separator = ":"; | |
foreach (var trimmedValue in header.Value.Select(headerValue => headerValue.Replace("\r\n", string.Empty))) | |
{ | |
builder.Append(string.Format("{0}{1}", separator, trimmedValue)); | |
separator = ","; | |
} | |
stringBuilder.Append(builder); | |
stringBuilder.Append("\n"); | |
} | |
return stringBuilder.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment