/// <summary> /// Set 'Content-MD5' http header. /// </summary> private void SetContentMd5(HttpRequestMessageBuilder requestBuilder) { if (requestBuilder.Method == HttpMethod.Put || requestBuilder.Method.Equals(HttpMethod.Post)) { var body = requestBuilder.Content; if (body == null) { return; } // For insecure, authenticated requests set sha256 header instead of MD5. if (!isSecure && !isAnonymous) { return; } // All anonymous access requests get Content-MD5 header set. var md5 = MD5.Create(); byte[] hash = md5.ComputeHash(body); string base64 = Convert.ToBase64String(hash); requestBuilder.AddBodyParameter("Content-MD5", base64); } }