fix web server OOM

This commit is contained in:
cottongin 2026-01-24 23:08:35 -05:00
parent 2b2bc95cf2
commit fedc14bcb4
No known key found for this signature in database
GPG Key ID: 0ECC91FE4655C262

View File

@ -221,7 +221,10 @@ void CrossPointWebServer::handleClient() const {
}
void CrossPointWebServer::handleRoot() const {
server->send(200, "text/html", HomePageHtml);
// Use chunked sending for consistency with handleFileList (avoids String allocation)
server->setContentLength(strlen(HomePageHtml));
server->send(200, "text/html", "");
server->sendContent_P(HomePageHtml);
Serial.printf("[%lu] [WEB] Served root page\n", millis());
}
@ -319,7 +322,14 @@ bool CrossPointWebServer::isEpubFile(const String& filename) const {
return lower.endsWith(".epub");
}
void CrossPointWebServer::handleFileList() const { server->send(200, "text/html", FilesPageHtml); }
void CrossPointWebServer::handleFileList() const {
// Use chunked sending to avoid allocating 64KB+ contiguous RAM for String conversion.
// The original server->send(200, "text/html", FilesPageHtml) fails when heap is fragmented
// because it tries to create a String from the large PROGMEM array.
server->setContentLength(strlen(FilesPageHtml));
server->send(200, "text/html", "");
server->sendContent_P(FilesPageHtml);
}
void CrossPointWebServer::handleFileListData() const {
// Get current path from query string (default to root)