diff --git a/generator/.DevConfigs/1505438c-c9a6-422f-85d8-0fa7258698f6.json b/generator/.DevConfigs/1505438c-c9a6-422f-85d8-0fa7258698f6.json new file mode 100644 index 000000000000..0e0d465aea95 --- /dev/null +++ b/generator/.DevConfigs/1505438c-c9a6-422f-85d8-0fa7258698f6.json @@ -0,0 +1,9 @@ +{ + "core": { + "changeLogMessages": [ + "Update HttpRequestMessageFactory to correctly set the Content-Length header" + ], + "type": "patch", + "updateMinimum": true + } +} \ No newline at end of file diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs index 4e43225ba9ff..f81f17e66ca5 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs @@ -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; } catch (NotSupportedException) { diff --git a/sdk/test/NetStandard/IntegrationTests/IntegrationTests/S3/PutObjectTests.cs b/sdk/test/NetStandard/IntegrationTests/IntegrationTests/S3/PutObjectTests.cs index f667be23571f..01bdac2032bf 100644 --- a/sdk/test/NetStandard/IntegrationTests/IntegrationTests/S3/PutObjectTests.cs +++ b/sdk/test/NetStandard/IntegrationTests/IntegrationTests/S3/PutObjectTests.cs @@ -189,8 +189,10 @@ public async Task PutObjectWithoutContentEncoding(bool useChunkEncoding) /// /// Reported in https://github.com/aws/aws-sdk-net/issues/3629 /// - [Fact] - public async Task TestResetStreamPosition() + [Theory] + [InlineData(true)] + [InlineData(false)] + public async Task TestResetStreamPosition(bool useChunkEncoding) { var memoryStream = new MemoryStream(); long offset; @@ -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);