Amazon.Runtime.Internal.Auth.AWS4Signer.SetRequestBodyHash C# (CSharp) 메소드

SetRequestBodyHash() 공개 정적인 메소드

If the caller has already set the x-amz-content-sha256 header with a pre-computed content hash, or it is present as ContentStreamHash on the request instance, return the value to be used in request canonicalization. If not set as a header or in the request, attempt to compute a hash based on inspection of the style of the request content.
public static SetRequestBodyHash ( IRequest request ) : string
request IRequest
리턴 string
        public static string SetRequestBodyHash(IRequest request)
        {
            string computedContentHash = null;
            var shaHeaderPresent = request.Headers.TryGetValue(HeaderKeys.XAmzContentSha256Header, out computedContentHash);
            if (shaHeaderPresent && !request.UseChunkEncoding)
                return computedContentHash;

            if (request.UseChunkEncoding)
            {
                computedContentHash = StreamingBodySha256;
                if (request.Headers.ContainsKey(HeaderKeys.ContentLengthHeader))
                {
                    // substitute the originally declared content length with the true size of
                    // the data we'll upload, which is inflated with chunk metadata
                    request.Headers[HeaderKeys.XAmzDecodedContentLengthHeader] = request.Headers[HeaderKeys.ContentLengthHeader];
                    var originalContentLength = long.Parse(request.Headers[HeaderKeys.ContentLengthHeader], CultureInfo.InvariantCulture);
                    request.Headers[HeaderKeys.ContentLengthHeader]
                        = ChunkedUploadWrapperStream.ComputeChunkedContentLength(originalContentLength).ToString(CultureInfo.InvariantCulture);
                }

                if (request.Headers.ContainsKey(HeaderKeys.ContentEncodingHeader))
                {
                    var originalEncoding = request.Headers[HeaderKeys.ContentEncodingHeader];
                    if (!originalEncoding.Contains(AWSChunkedEncoding))
                    {
                        request.Headers[HeaderKeys.ContentEncodingHeader]
                        = string.Concat(originalEncoding, ", ", AWSChunkedEncoding);
                    }
                }
                else
                    request.Headers[HeaderKeys.ContentEncodingHeader] = AWSChunkedEncoding;
            }
            else
            {
                if (request.ContentStream != null)
                    computedContentHash = request.ComputeContentStreamHash();
                else
                {
                    byte[] payloadBytes = GetRequestPayloadBytes(request);
                    byte[] payloadHashBytes = CryptoUtilFactory.CryptoInstance.ComputeSHA256Hash(payloadBytes);
                    computedContentHash = AWSSDKUtils.ToHex(payloadHashBytes, true);
                }
            }

            if (computedContentHash != null)
            {
                if (shaHeaderPresent)
                    request.Headers[HeaderKeys.XAmzContentSha256Header] = computedContentHash;
                else
                    request.Headers.Add(HeaderKeys.XAmzContentSha256Header, computedContentHash);
            }

            return computedContentHash;
        }