Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ac9e5d9

Browse files
committed
[HIGH PRIORITY - Proposed fix to be included for ASP.NET Beta7]
This fixes a bug found with chunked uploads using custom content that repeatedly calls Flush() on the stream passed into SerializeToStreamAsync. This bug was discovered by WCF tests and reported via GitHub: https://github.com/dotnet/corefx/issues/2897 It was a mistake to use the Flush() method on the stream to send the final terminating chunk for the upload since that method can be called by custom content via the SerializeToStreamAsync method. The typical use pattern is that depending on the actual streams involved, upper layer software typically can call Flush() one or more times when writing to a stream. The fix here is to simply leave Flush() as a no-op (which it basically is for the WinHttpRequestStream) and have an internal method to handle the writing of the final terminating chunk. This fix is being checked into TFS instead of using a GitHub PR. The reason is that the tests for this need to use our current internal server that correctly echoes the request headers in order to verify 'Transfer-Encoding: chunked' was sent by the client. I tried to put this test into the current GitHub tests using the current "http://httpbin.org" test server, but I discovered that httpbin.org doesn't properly echo the request headers when 'Transfer-Encoding' is sent. Instead, it ends up replacing that header and sending back 'Content-Length' (even though we didn't send that in the request headers). We have a backlog work item to port our remaining ToF tests to GitHub over the next several weeks. [tfs-changeset: 1516976]
1 parent 89fe66d commit ac9e5d9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ private async void StartRequest(object obj)
11901190
await state.RequestMessage.Content.CopyToAsync(
11911191
requestStream,
11921192
state.TransportContext).ConfigureAwait(false);
1193-
requestStream.Flush();
1193+
requestStream.EndUpload();
11941194
}
11951195

11961196
state.CancellationToken.ThrowIfCancellationRequested();

src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpRequestStream.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ public override long Position
7777

7878
public override void Flush()
7979
{
80-
if (_chunkedMode)
81-
{
82-
WriteData(s_endChunk, 0, s_endChunk.Length);
83-
}
8480
}
8581

8682
public override void Write(byte[] buffer, int offset, int count)
@@ -128,6 +124,14 @@ public override int Read(byte[] buffer, int offset, int count)
128124
throw new NotSupportedException();
129125
}
130126

127+
internal void EndUpload()
128+
{
129+
if (_chunkedMode)
130+
{
131+
WriteData(s_endChunk, 0, s_endChunk.Length);
132+
}
133+
}
134+
131135
protected override void Dispose(bool disposing)
132136
{
133137
if (disposing && !_disposed)

0 commit comments

Comments
 (0)