chunked response works now - but does not solve my problem >:(

This commit is contained in:
Marcus 2024-10-26 04:33:27 +02:00
parent f7c4739f0d
commit 10a0906a93

View file

@ -398,7 +398,7 @@ String Proc_WebPage_system_output_add_POST(const String& var) {
}
// https://github.com/mathieucarbou/ESPAsyncWebServer?tab=readme-ov-file#chunked-response-containing-templates
auto Chunk_system_output_add_HTML(uint8_t *buffer, size_t maxLen, size_t alreadySent) -> size_t {
//auto Chunk_system_output_add_HTML(uint8_t *buffer, size_t maxLen, size_t alreadySent) -> 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
@ -406,32 +406,40 @@ auto Chunk_system_output_add_HTML(uint8_t *buffer, size_t maxLen, size_t already
// https://forum.arduino.cc/t/espasyncwebserver-replay-page-size/1049106/19
//const int len_html = sizeof(Page_system_output_add_HTML)/sizeof(Page_system_output_add_HTML[0]);
//size_t len = min(maxLen, String(Page_system_output_add_HTML).length() - index);
//size_t len = min(maxLen, len_html - index);
//Serial.printf("Sending %u bytes\n", len);
//memcpy(buffer, String(Page_system_output_add_HTML).c_str() + index, len);
//memcpy(buffer, Page_system_output_add_HTML + index, len);
//return len;
const size_t size = sizeof Page_system_output_add_HTML;
if (size - alreadySent >= maxLen) {
memcpy(buffer, Page_system_output_add_HTML + alreadySent, maxLen);
return maxLen;
} else { // last chunk and then 0
memcpy(buffer, Page_system_output_add_HTML + alreadySent, size - alreadySent);
return size - alreadySent;
}
}
//const size_t size = sizeof Page_system_output_add_HTML;
//if (size - alreadySent >= maxLen) {
//memcpy(buffer, Page_system_output_add_HTML + alreadySent, maxLen);
//return maxLen;
//} else { // last chunk and then 0
//memcpy(buffer, Page_system_output_add_HTML + alreadySent, size - alreadySent);
//return size - alreadySent;
//}
//}
void WebPage_system_output_add(AsyncWebServerRequest *request) {
if(request->method() == HTTP_POST) {
AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", Chunk_system_output_add_HTML);
request->send(response);
//AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", Chunk_system_output_add_HTML, Proc_WebPage_system_output_add);
//request->send(response);
Serial.println(":: [Webserver:system:output:add] [POST] hello");
} else {
request->beginChunkedResponse("text/html", Chunk_system_output_add_HTML);
AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", [](uint8_t *buffer, size_t maxlen, size_t index) -> size_t {
// https://forum.arduino.cc/t/strlen-and-progmem/629376/3
size_t len_html = strlen_P(reinterpret_cast<const char *>(Page_system_output_add_HTML));
size_t len = min(maxlen, len_html - index);
Serial.printf(":: [Webserver:system:output:add(Chunked)] Sending len %u bytes , maxlen %u, index %u, sizeof %u\n", len, maxlen, index, len_html);
memcpy(buffer, Page_system_output_add_HTML + index, len);
return len;
}, Proc_WebPage_system_output_add);
request->send(response);
}
}