mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
.NET Stream.Read() semantics leave it to the implementation to decide how much data to return given a buffer of size N: https://msdn.microsoft.com/en-us/library/system.io.stream.read(v=vs.110).aspx "An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached." The behavior of System.Net HTTP APIs (i.e. .NET Framework) are such that stream reads are able to return as soon as data is available. They don't wait until the provided buffer is full. The current WinHttpHandler was not behaving that way because it didn't call WinHttpQueryDataAvailable before calling WinHttpReadData. WinHttpQueryDataAvailable would indicate how many bytes can be read immediately. This fix changes the WinHttpResponseStream.Read* methods to use WinHttpQueryDataAvailable before calling WinHttpReadData. Added both WinHttpHandler unit tests (helps with simulating/testing network errors) and HttpClientHandler functional tests (which will test x-plat). Fixes dotnet/corefx#1825 Commit migrated from https://github.com/dotnet/corefx/commit/5386014a6b74a8d38010b244f9e9ced96df53b69