Closed
Description
openedon Jun 1, 2018
Since 2.1.300, setting ExpectContinue
to true
will cause Read
operations on the response stream to block for a long period rather than immediately returning 0 at the end of stream content.
Reproduction:
using System;
using System.IO;
using System.Net;
using System.Net.Http;
namespace http_response_read_test
{
class Program
{
private const int buffer_size = 2048;
static void Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.ExpectContinue = true;
var response = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, "https://httpbin.org/get")).Result;
var buffer = new byte[buffer_size];
using (var responseStream = response.Content.ReadAsStreamAsync().Result)
{
int read;
while ((read = responseStream.Read(buffer, 0, buffer_size)) > 0)
{
// consume buffer
}
}
System.Console.WriteLine("finished");
}
}
}
Running this code under netcoreapp2.0
and net471
will exit immediately after the response is read, while running under netcoreapp2.1
will block for a very long time before eventually exiting (takes around a minute).
Commenting out the ExpectContinue
line will cause all three runtimes to match in behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment