Skip to content

Update HttpRequestMessageFactory to correctly set the Content-Length header #3768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"core": {
"changeLogMessages": [
"Update HttpRequestMessageFactory to correctly set the Content-Length header"
],
"type": "patch",
"updateMinimum": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,12 @@ public void WriteToRequestBody(HttpContent requestContent, Stream contentStream,
if ((isChunkedUploadWrapperStreamWithLength || isTrailingHeadersWrapperStreamWithLength || isCompressionWrapperStreamWithLength)
|| (chunkedUploadWrapperStream == null && trailingHeadersWrapperStream == null && compressionWrapperStream == null))
{
long position = 0;
long position;
try
{
if (contentStream.CanSeek)
{
position = contentStream.Position;
}
// Even in cases where the stream is unseekable the position may still be tracked due to special
// circumstances of ChunkedUploadWrapperStream.
position = contentStream.Position;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not relying on the CanSeek is due to special circumstances of our ChunkedUploadWrapperStream. You might want to add a comment here so somebody in the future, like myself, don't suggest adding back the CanSeek check to avoid the control flow by exception.

}
catch (NotSupportedException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ public async Task PutObjectWithoutContentEncoding(bool useChunkEncoding)
/// <summary>
/// Reported in https://github.com/aws/aws-sdk-net/issues/3629
/// </summary>
[Fact]
public async Task TestResetStreamPosition()
[Theory]
[InlineData(true)]
[InlineData(false)]
public async Task TestResetStreamPosition(bool useChunkEncoding)
{
var memoryStream = new MemoryStream();
long offset;
Expand All @@ -214,7 +216,7 @@ public async Task TestResetStreamPosition()
AutoResetStreamPosition = false,
AutoCloseStream = !memoryStream.CanSeek,
InputStream = memoryStream.CanSeek ? memoryStream : AmazonS3Util.MakeStreamSeekable(memoryStream),
UseChunkEncoding = false,
UseChunkEncoding = useChunkEncoding,
};

var putResponse = await Client.PutObjectAsync(putRequest);
Expand Down