me-no-dev / ESPAsyncWebServer

Async Web Server for ESP8266 and ESP32
3.7k stars 1.21k forks source link

Buffer chunked response #1376

Open ddprog opened 7 months ago

ddprog commented 7 months ago

Hello. I would like to understand the chunked response. I use the code from the example, the function returns the size of the buffer (in bytes).

AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
  //Write up to "maxLen" bytes into "buffer" and return the amount written.
  //index equals the amount of bytes that have been already sent
  //You will be asked for more data until 0 is returned
  //Keep in mind that you can not delay or yield waiting for more data!
  return mySource.read(buffer, maxLen);
});
response->addHeader("Server","ESP Async Web Server");
request->send(response);

If it is filled almost completely, the controller reboots - tcpasync did not reset the watchdog timer in time. If you put about 1/10 of that size into the buffer, then everything is fine. The question is - how much should be given to the buffer?