public static string CanonicalizeHttpRequestVer1(Uri address, NephosUriComponents uriComponents, string method, string contentEncoding, string contentLanguage, string contentLength, string contentMD5, string contentType, string date, string ifModifiedSince, string ifMatch, string ifNoneMatch, string ifUnmodifiedSince, string range, NameValueCollection headers, bool isFileService = false, string rawUrl = null, bool multipleConditionalHeadersEnabled = false) { NephosAssertionException.Assert(address != null); NephosAssertionException.Assert(uriComponents != null); NephosAssertionException.Assert(!string.IsNullOrEmpty(method)); NephosAssertionException.Assert(headers != null); MessageCanonicalizer.CanonicalizedString canonicalizedString = new MessageCanonicalizer.CanonicalizedString(method); canonicalizedString.AppendCanonicalizedElement(contentEncoding ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(contentLanguage ?? string.Empty); if (contentLength == null || !MessageCanonicalizer.IsVersionBeforeFeb15(headers) && contentLength.Equals("0")) { canonicalizedString.AppendCanonicalizedElement(string.Empty); } else { canonicalizedString.AppendCanonicalizedElement(contentLength); } canonicalizedString.AppendCanonicalizedElement(contentMD5 ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(contentType ?? string.Empty); if (headers["x-ms-date"] != null) { canonicalizedString.AppendCanonicalizedElement(string.Empty); } else { canonicalizedString.AppendCanonicalizedElement(date ?? string.Empty); } canonicalizedString.AppendCanonicalizedElement(ifModifiedSince ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(ifMatch ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(ifNoneMatch ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(ifUnmodifiedSince ?? string.Empty); canonicalizedString.AppendCanonicalizedElement(range ?? string.Empty); ArrayList arrayLists = new ArrayList(); foreach (string key in headers.Keys) { if (key == null || !key.ToLowerInvariant().StartsWith("x-ms-", StringComparison.Ordinal)) { continue; } arrayLists.Add(key.ToLowerInvariant()); } arrayLists.Sort(); foreach (string arrayList in arrayLists) { string canonicalizedHeaderValueVer1 = MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, arrayList, multipleConditionalHeadersEnabled); if (string.IsNullOrEmpty(canonicalizedHeaderValueVer1) && !isFileService && MessageCanonicalizer.IsVersionBeforeFeb16(headers["x-ms-version"])) { continue; } StringBuilder stringBuilder = new StringBuilder(arrayList); stringBuilder.Append(":"); stringBuilder.Append(canonicalizedHeaderValueVer1); canonicalizedString.AppendCanonicalizedElement(stringBuilder.ToString()); } canonicalizedString.AppendCanonicalizedElement(MessageCanonicalizer.GetCanonicalizedResourceVer1(address, uriComponents, rawUrl)); return(canonicalizedString.Value); }
public static string CanonicalizeHttpRequestVer1(Uri uri, NephosUriComponents uriComponents, string method, NameValueCollection headers, bool isFileService = false, string rawUrl = null, bool multipleConditionalHeadersEnabled = false) { return(MessageCanonicalizer.CanonicalizeHttpRequestVer1(uri, uriComponents, method, MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Encoding", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Language", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Length", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-MD5", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Content-Type", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Date", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Modified-Since", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Match", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-None-Match", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "If-Unmodified-Since", multipleConditionalHeadersEnabled), MessageCanonicalizer.GetCanonicalizedHeaderValueVer1(headers, "Range", multipleConditionalHeadersEnabled), headers, isFileService, rawUrl, multipleConditionalHeadersEnabled)); }