runtime icon indicating copy to clipboard operation
runtime copied to clipboard

WinHttpRequestStream.Flush Appends "0\r\n\r\n" in Chunked Mode

Open shmao opened this issue 11 years ago • 5 comments

WinHttpRequestStream.Flush writes "0\r\n\r\n" to the stream every time the method is called in when _chunkedMode is true. This behavior seems wrong. The _endChunk should only be added to the end.

shmao avatar Aug 20 '15 01:08 shmao

Because of this behavior WCF intermittently gets error saying 'The server returned an invalid or unrecognized response' (see dotnet/wcf#287.)

shmao avatar Aug 20 '15 01:08 shmao

cc: @CIPop @SidharthNabar

davidsh avatar Aug 20 '15 02:08 davidsh

@shmao Native WinHTTP doesn't handle chunked uploads on its own. So, we needed to implement the chunked encoding ourselves. The WinHttpRequestStream.Flush() method was meant to be called only once internally. I'll need to look at the repro to understand how it is being called multiple times. The stream itself is internal but perhaps it is being exposed thru the SerializeToStreamAsync() protected method and that custom HttpContent class is calling it multiple times?

davidsh avatar Aug 20 '15 02:08 davidsh

@davidsh Yes, you were right. The stream can be accessed by inherited 'HttpContent' through 'SerializeToStreamAsync', and the 'Flush()' method can possibly be called at many places. You can have a look at the call stack of this test, which failed because of the issue.

shmao avatar Aug 20 '15 06:08 shmao

Will be fixed as of PR dotnet/corefx#2907

davidsh avatar Aug 21 '15 02:08 davidsh