I'm creating an Azure Function that returns chunked response (using await response.WriteAsync(...)
). When I open the Azure Function URL in Chrome I'm getting the error:
Chunked:1 GET http://localhost:7071/api/Chunked net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)
This error happens most of the times, but sometime I'm getting the correct result. However, when I open the same URL from Edge, the response is always loaded correctly. I'm running the code locally from Visual Studio 15.8.7, Function Runtime Version: 2.0.12134.0,
I created a minimal repro:
[FunctionName("Chunked")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var res = req.HttpContext.Response;
res.StatusCode = 200;
var token = " Lorem ipsum ";
await res.WriteAsync(token);
for (int i = 0; i < 100; i++)
{
token += token;
if (token.Length > 2000)
token = " Lorem ipsum ";
await res.WriteAsync(i + token + "\n");
await Task.Delay(10); // Simulate wait for another record
}
}
My code is more complex because it reads the content from database, but I simulated it with Task.Delay.