Ejemplo n.º 1
0
        /// <summary>
        /// Checks the validity of the contents MD5 hash.
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static async Task <bool> IsMd5Valid(this HttpContent content)
        {
            if (content == null)
            {
                // No content so we are correct.
                return(true);
            }

            var hashHeader = content.Headers.ContentMD5;

            if (hashHeader == null)
            {
                // TOOD: Should we always require one if we have non-null content?
                // No MD5 hash so true
                return(true);
            }

            var hash = await content.ComputeMd5Hash();

            return(hash.SequenceEqual(hashHeader));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compute and assign the MD5 hash of the content.
        /// </summary>
        /// <param name="httpContent"></param>
        /// <returns></returns>
        public static async Task AssignMd5Hash(this HttpContent httpContent)
        {
            var hash = await httpContent.ComputeMd5Hash();

            httpContent.Headers.ContentMD5 = hash;
        }