Skip to content

Commit

Permalink
fix: Update HttpWebRequestMessage to handle MD5Stream (which does not…
Browse files Browse the repository at this point in the history
… support seeking)
  • Loading branch information
dscpinheiro committed Feb 7, 2025
1 parent 5620f97 commit 780ed4e
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,20 @@ public void WriteToRequestBody(HttpContent requestContent, Stream contentStream,
if ((isChunkedUploadWrapperStreamWithLength || isTrailingHeadersWrapperStreamWithLength || isCompressionWrapperStreamWithLength)
|| (chunkedUploadWrapperStream == null && trailingHeadersWrapperStream == null && compressionWrapperStream == null))
{
_request.Content.Headers.ContentLength = contentStream.Length - contentStream.Position;
long position;
try
{
position = contentStream.Position;
}
catch (NotSupportedException)
{
// If this method is invoked from an older service package, the content stream may not support getting the
// current position (for example, "MD5Stream" doesn't).
// In this case, we'll assume the position is 0 to maintain the previous behavior.
position = 0;
}

_request.Content.Headers.ContentLength = contentStream.Length - position;
}

WriteContentHeaders(contentHeaders);
Expand Down

0 comments on commit 780ed4e

Please sign in to comment.