This question is a little older, but nowhere could I find a better answer to what I was trying to do. I realized that the trick is to open a new StreamWriter for every piece of content that you would like to write. Just do the following:
[HttpDelete]
public void Content()
{
Response.StatusCode = 200;
Response.ContentType = "text/html";
using (var sw = StreamWriter.Synchronized(new StreamWriter(Response.Body)))
{
foreach (var item in new int[] { 1, 2, 3, 4, })
{
Thread.Sleep(1000);
sw.Write($"<p>Hi there {item}!</p>");
sw.Flush();
}
};
}
you can check with curl with the following command: curl -NX DELETE <CONTROLLER_ROUTE>/content
source
share