本文整理汇总了C#中IRequest.ComputeContentStreamHash方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.ComputeContentStreamHash方法的具体用法?C# IRequest.ComputeContentStreamHash怎么用?C# IRequest.ComputeContentStreamHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRequest
的用法示例。
在下文中一共展示了IRequest.ComputeContentStreamHash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetRequestBodyHash
/// <summary>
/// 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.
/// </summary>
/// <param name="request"></param>
/// <returns>
/// The computed hash, whether already set in headers or computed here. Null
/// if we were not able to compute a hash.
/// </returns>
public static string SetRequestBodyHash(IRequest request)
{
string computedContentHash = null;
if (request.Headers.TryGetValue(XAmzContentSha256, out computedContentHash))
return computedContentHash;
if (request.UseChunkEncoding)
{
computedContentHash = StreamingBodySha256;
if (request.Headers.ContainsKey("Content-Length"))
{
// substitute the originally declared content length with the true size of
// the data we'll upload, which is inflated with chunk metadata
request.Headers[XAmzDecodedContentLength] = request.Headers["Content-Length"];
var originalContentLength = long.Parse(request.Headers["Content-Length"], CultureInfo.InvariantCulture);
request.Headers["Content-Length"]
= ChunkedUploadWrapperStream.ComputeChunkedContentLength(originalContentLength).ToString(CultureInfo.InvariantCulture);
}
request.Headers["Content-Encoding"] = "aws-chunked";
}
else
{
if (request.ContentStream != null)
computedContentHash = request.ComputeContentStreamHash();
else
{
byte[] payloadHashBytes;
if (request.Content != null)
payloadHashBytes = CryptoUtilFactory.CryptoInstance.ComputeSHA256Hash(request.Content);
else
{
var payload = request.UseQueryString ? "" : GetRequestPayload(request);
payloadHashBytes = CryptoUtilFactory.CryptoInstance.ComputeSHA256Hash(Encoding.UTF8.GetBytes(payload));
}
computedContentHash = AWSSDKUtils.ToHex(payloadHashBytes, true);
}
}
if (computedContentHash != null)
request.Headers.Add(XAmzContentSha256, computedContentHash);
return computedContentHash;
}
示例2: SetRequestBodyHash
/// <summary>
/// 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.
/// </summary>
/// <param name="request"></param>
/// <returns>
/// The computed hash, whether already set in headers or computed here. Null
/// if we were not able to compute a hash.
/// </returns>
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;
}
示例3: SetRequestBodyHash
/// <summary>
/// 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.
/// </summary>
/// <param name="request"></param>
/// <returns>
/// The computed hash, whether already set in headers or computed here. Null
/// if we were not able to compute a hash.
/// </returns>
public static string SetRequestBodyHash(IRequest request)
{
string computedContentHash = null;
if (request.Headers.TryGetValue(XAmzContentSha256, out computedContentHash))
return computedContentHash;
if (request.ContentStream != null)
computedContentHash = request.ComputeContentStreamHash();
else
{
byte[] payloadHashBytes;
if (request.Content != null)
payloadHashBytes = CryptoUtilFactory.CryptoInstance.ComputeSHA256Hash(request.Content);
else
{
var payload = request.UseQueryString ? "" : GetRequestPayload(request);
payloadHashBytes = CryptoUtilFactory.CryptoInstance.ComputeSHA256Hash(Encoding.UTF8.GetBytes(payload));
}
computedContentHash = AWSSDKUtils.ToHex(payloadHashBytes, true);
}
if (computedContentHash != null)
request.Headers.Add(XAmzContentSha256, computedContentHash);
return computedContentHash;
}