-
-
Save bwatts/5691810 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 headers = | |
from header in httpClient.DefaultRequestHeaders | |
where header.Key.StartsWith("x-ms-", StringComparison.InvariantCultureIgnoreCase) | |
orderby header.Key | |
select new | |
{ | |
Key = header.Key, | |
Values = header.Value.Select(value => value.Replace(Environment.Newline, "")) | |
}; | |
var headerText = new StringBuilder(); | |
foreach(var header in headers) | |
{ | |
headerText.Append(header.Key); | |
var separator = ":"; | |
foreach(var value in header.Values) | |
{ | |
builder.Append(separator).Append(value); | |
separator = ","; | |
} | |
headerText.AppendLine(); | |
} | |
return headerText.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment