コード例 #1
0
        public string CanonicalizeHttpRequest(HttpRequestMessage request, string accountName)
        {
            CommonUtility.AssertNotNull("request", request);
            CanonicalizedString canonicalizedString = new CanonicalizedString(request.Method.Method);

            if (request.Content != null && request.Content.Headers.ContentMD5 != null)
            {
                canonicalizedString.AppendCanonicalizedElement(Convert.ToBase64String(request.Content.Headers.ContentMD5));
            }
            else
            {
                canonicalizedString.AppendCanonicalizedElement(null);
            }
            if (request.Content != null && request.Content.Headers.ContentType != null)
            {
                canonicalizedString.AppendCanonicalizedElement(request.Content.Headers.ContentType.ToString());
            }
            else
            {
                canonicalizedString.AppendCanonicalizedElement(null);
            }
            AuthenticationUtility.AppendCanonicalizedDateHeader(canonicalizedString, request, allowMicrosoftDateHeader: true);
            string canonicalizedResourceString = AuthenticationUtility.GetCanonicalizedResourceString(request.RequestUri, accountName);

            canonicalizedString.AppendCanonicalizedElement(canonicalizedResourceString);
            return(canonicalizedString.ToString());
        }
コード例 #2
0
        public static void AppendCanonicalizedDateHeader(CanonicalizedString canonicalizedString, HttpRequestMessage request, bool allowMicrosoftDateHeader = false)
        {
            string headerSingleValueOrDefault = request.Headers.GetHeaderSingleValueOrDefault("x-ms-date");

            if (string.IsNullOrEmpty(headerSingleValueOrDefault))
            {
                canonicalizedString.AppendCanonicalizedElement(GetCanonicalizedHeaderValue(request.Headers.Date));
            }
            else if (allowMicrosoftDateHeader)
            {
                canonicalizedString.AppendCanonicalizedElement(headerSingleValueOrDefault);
            }
            else
            {
                canonicalizedString.AppendCanonicalizedElement(null);
            }
        }