mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-09-30 08:10:56 +02:00
add slow chunk example
This commit is contained in:
@@ -503,6 +503,27 @@ void setup() {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// time curl -N -v -X GET http://192.168.4.1/slow.html --output -
|
||||||
|
server.on("/slow.html", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
request->client()->setRxTimeout(2000);
|
||||||
|
AsyncWebServerResponse* response = request->beginChunkedResponse("text/html", [](uint8_t* buffer, size_t maxLen, size_t index) -> size_t {
|
||||||
|
Serial.printf("%u\n", index);
|
||||||
|
// finished ?
|
||||||
|
if (index >= 160000)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// slow down the task by 2 seconds
|
||||||
|
// to simulate some heavy processing, like SD card reading
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
memset(buffer, characters[charactersIndex], 256);
|
||||||
|
charactersIndex = (charactersIndex + 1) % sizeof(characters);
|
||||||
|
return 256;
|
||||||
|
});
|
||||||
|
|
||||||
|
request->send(response);
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
❯ curl -I -X HEAD http://192.168.4.1/download
|
❯ curl -I -X HEAD http://192.168.4.1/download
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
|
Reference in New Issue
Block a user