diff --git a/src/network/CrossPointWebServer.cpp b/src/network/CrossPointWebServer.cpp index 01e1e48..8f5d844 100644 --- a/src/network/CrossPointWebServer.cpp +++ b/src/network/CrossPointWebServer.cpp @@ -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)