bbx10/WebServer_tng

serving page from flash stops after 5727 bytes

everslick opened this issue · 8 comments

I serve static html code directly from flash (PSTR()), for example an approx. 6KB big style.css file. But the html code is not sent beyond 5727 bytes.

The exact same html code worked on ESP8266.

For testing purposes is split the CSS file into two smaller parts, and everything started to work smoothly.

bbx10 commented

ESP32 does not support PROGMEM. It does have pgmspace.h and macros such as PSTR and PROGMEM for backwards compatibility with ESP8266. But they do nothing on ESP32.

Post a small program that shows the problem.

ok, didn't know about the PROGMEM, thanks for the clarification. :-) do you know, if it isn't possible to support PROGMEM on ESP32 or if it is just not so important, because ESP32 has much more RAM?

anyway i made a minimal sketch that reproduces the bug, at least here on my site.

#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>

WebServer server(80);

const char* ssid = "........";
const char* password = "........";

#define HEADER \
  "<!DOCTYPE html>\n" \
  "<html>\n" \
  "<head>\n" \
  "<title>WebTest</title>\n" \
  "<meta name='viewport' content='width=device-width, initial-scale=1'>\n" \
  "</head>\n" \
  "<body>\n"

#define FOOTER \
  "</body>\n" \
  "</html>\n"

void handleRoot() {
  server.send(200, "text/html",
    HEADER
    "<a href='/big.html'>BIG FILE</a><br>"
    "<a href='/small.html'>SMALL FILE</a>"
    FOOTER
  );
}
void handleBig() {
  server.send(200, "text/html",
    HEADER
    "0001:    012345678901234567890123456789012345678901234567890123456789\n"
    "0002:    012345678901234567890123456789012345678901234567890123456789\n"
    "0003:    012345678901234567890123456789012345678901234567890123456789\n"
    "0005:    012345678901234567890123456789012345678901234567890123456789\n"
    "0006:    012345678901234567890123456789012345678901234567890123456789\n"
    "0007:    012345678901234567890123456789012345678901234567890123456789\n"
    "0008:    012345678901234567890123456789012345678901234567890123456789\n"
    "0009:    012345678901234567890123456789012345678901234567890123456789\n"
    "0010:    012345678901234567890123456789012345678901234567890123456789\n"
    "0011:    012345678901234567890123456789012345678901234567890123456789\n"
    "0012:    012345678901234567890123456789012345678901234567890123456789\n"
    "0013:    012345678901234567890123456789012345678901234567890123456789\n"
    "0014:    012345678901234567890123456789012345678901234567890123456789\n"
    "0015:    012345678901234567890123456789012345678901234567890123456789\n"
    "0016:    012345678901234567890123456789012345678901234567890123456789\n"
    "0017:    012345678901234567890123456789012345678901234567890123456789\n"
    "0018:    012345678901234567890123456789012345678901234567890123456789\n"
    "0019:    012345678901234567890123456789012345678901234567890123456789\n"
    "0020:    012345678901234567890123456789012345678901234567890123456789\n"
    "0021:    012345678901234567890123456789012345678901234567890123456789\n"
    "0022:    012345678901234567890123456789012345678901234567890123456789\n"
    "0023:    012345678901234567890123456789012345678901234567890123456789\n"
    "0024:    012345678901234567890123456789012345678901234567890123456789\n"
    "0025:    012345678901234567890123456789012345678901234567890123456789\n"
    "0026:    012345678901234567890123456789012345678901234567890123456789\n"
    "0027:    012345678901234567890123456789012345678901234567890123456789\n"
    "0028:    012345678901234567890123456789012345678901234567890123456789\n"
    "0029:    012345678901234567890123456789012345678901234567890123456789\n"
    "0030:    012345678901234567890123456789012345678901234567890123456789\n"
    "0041:    012345678901234567890123456789012345678901234567890123456789\n"
    "0042:    012345678901234567890123456789012345678901234567890123456789\n"
    "0043:    012345678901234567890123456789012345678901234567890123456789\n"
    "0044:    012345678901234567890123456789012345678901234567890123456789\n"
    "0045:    012345678901234567890123456789012345678901234567890123456789\n"
    "0046:    012345678901234567890123456789012345678901234567890123456789\n"
    "0047:    012345678901234567890123456789012345678901234567890123456789\n"
    "0048:    012345678901234567890123456789012345678901234567890123456789\n"
    "0049:    012345678901234567890123456789012345678901234567890123456789\n"
    "0050:    012345678901234567890123456789012345678901234567890123456789\n"
    "0051:    012345678901234567890123456789012345678901234567890123456789\n"
    "0052:    012345678901234567890123456789012345678901234567890123456789\n"
    "0053:    012345678901234567890123456789012345678901234567890123456789\n"
    "0054:    012345678901234567890123456789012345678901234567890123456789\n"
    "0055:    012345678901234567890123456789012345678901234567890123456789\n"
    "0056:    012345678901234567890123456789012345678901234567890123456789\n"
    "0057:    012345678901234567890123456789012345678901234567890123456789\n"
    "0058:    012345678901234567890123456789012345678901234567890123456789\n"
    "0059:    012345678901234567890123456789012345678901234567890123456789\n"
    "0060:    012345678901234567890123456789012345678901234567890123456789\n"
    "0061:    012345678901234567890123456789012345678901234567890123456789\n"
    "0062:    012345678901234567890123456789012345678901234567890123456789\n"
    "0063:    012345678901234567890123456789012345678901234567890123456789\n"
    "0064:    012345678901234567890123456789012345678901234567890123456789\n"
    "0065:    012345678901234567890123456789012345678901234567890123456789\n"
    "0066:    012345678901234567890123456789012345678901234567890123456789\n"
    "0067:    012345678901234567890123456789012345678901234567890123456789\n"
    "0068:    012345678901234567890123456789012345678901234567890123456789\n"
    "0069:    012345678901234567890123456789012345678901234567890123456789\n"
    "0070:    012345678901234567890123456789012345678901234567890123456789\n"
    "0071:    012345678901234567890123456789012345678901234567890123456789\n"
    "0072:    012345678901234567890123456789012345678901234567890123456789\n"
    "0073:    012345678901234567890123456789012345678901234567890123456789\n"
    "0074:    012345678901234567890123456789012345678901234567890123456789\n"
    "0075:    012345678901234567890123456789012345678901234567890123456789\n"
    "0076:    012345678901234567890123456789012345678901234567890123456789\n"
    "0077:    012345678901234567890123456789012345678901234567890123456789\n"
    "0078:    012345678901234567890123456789012345678901234567890123456789\n"
    "0079:    012345678901234567890123456789012345678901234567890123456789\n"
    "0080:    012345678901234567890123456789012345678901234567890123456789\n"
    "0081:    012345678901234567890123456789012345678901234567890123456789\n"
    "0082:    012345678901234567890123456789012345678901234567890123456789\n"
    "0083:    012345678901234567890123456789012345678901234567890123456789\n"
    "0084:    012345678901234567890123456789012345678901234567890123456789\n"
    "0085:    012345678901234567890123456789012345678901234567890123456789\n"
    "0086:    012345678901234567890123456789012345678901234567890123456789\n"
    "0087:    012345678901234567890123456789012345678901234567890123456789\n"
    "0088:    012345678901234567890123456789012345678901234567890123456789\n"
    "0089:    012345678901234567890123456789012345678901234567890123456789\n"
    "0090:    012345678901234567890123456789012345678901234567890123456789\n"
    "0091:    012345678901234567890123456789012345678901234567890123456789\n"
    "0092:    012345678901234567890123456789012345678901234567890123456789\n"
    "0093:    012345678901234567890123456789012345678901234567890123456789\n"
    "0094:    012345678901234567890123456789012345678901234567890123456789\n"
    "0095:    012345678901234567890123456789012345678901234567890123456789\n"
    "0096:    012345678901234567890123456789012345678901234567890123456789\n"
    "0097:    012345678901234567890123456789012345678901234567890123456789\n"
    "0098:    012345678901234567890123456789012345678901234567890123456789\n"
    "0099:    012345678901234567890123456789012345678901234567890123456789\n"
    "0100:    012345678901234567890123456789012345678901234567890123456789\n"
    FOOTER
  );
}
void handleSmall() {
  server.send(200, "text/html",
    HEADER
    "0001:    012345678901234567890123456789012345678901234567890123456789\n"
    "0002:    012345678901234567890123456789012345678901234567890123456789\n"
    "0003:    012345678901234567890123456789012345678901234567890123456789\n"
    "0005:    012345678901234567890123456789012345678901234567890123456789\n"
    "0006:    012345678901234567890123456789012345678901234567890123456789\n"
    "0007:    012345678901234567890123456789012345678901234567890123456789\n"
    "0008:    012345678901234567890123456789012345678901234567890123456789\n"
    "0009:    012345678901234567890123456789012345678901234567890123456789\n"
    "0010:    012345678901234567890123456789012345678901234567890123456789\n"
    "0011:    012345678901234567890123456789012345678901234567890123456789\n"
    "0012:    012345678901234567890123456789012345678901234567890123456789\n"
    "0013:    012345678901234567890123456789012345678901234567890123456789\n"
    "0014:    012345678901234567890123456789012345678901234567890123456789\n"
    "0015:    012345678901234567890123456789012345678901234567890123456789\n"
    "0016:    012345678901234567890123456789012345678901234567890123456789\n"
    "0017:    012345678901234567890123456789012345678901234567890123456789\n"
    "0018:    012345678901234567890123456789012345678901234567890123456789\n"
    "0019:    012345678901234567890123456789012345678901234567890123456789\n"
    "0020:    012345678901234567890123456789012345678901234567890123456789\n"
    "0021:    012345678901234567890123456789012345678901234567890123456789\n"
    "0022:    012345678901234567890123456789012345678901234567890123456789\n"
    "0023:    012345678901234567890123456789012345678901234567890123456789\n"
    "0024:    012345678901234567890123456789012345678901234567890123456789\n"
    "0025:    012345678901234567890123456789012345678901234567890123456789\n"
    "0026:    012345678901234567890123456789012345678901234567890123456789\n"
    "0027:    012345678901234567890123456789012345678901234567890123456789\n"
    "0028:    012345678901234567890123456789012345678901234567890123456789\n"
    "0029:    012345678901234567890123456789012345678901234567890123456789\n"
    "0030:    012345678901234567890123456789012345678901234567890123456789\n"
    "0041:    012345678901234567890123456789012345678901234567890123456789\n"
    "0042:    012345678901234567890123456789012345678901234567890123456789\n"
    "0043:    012345678901234567890123456789012345678901234567890123456789\n"
    "0044:    012345678901234567890123456789012345678901234567890123456789\n"
    "0045:    012345678901234567890123456789012345678901234567890123456789\n"
    "0046:    012345678901234567890123456789012345678901234567890123456789\n"
    "0047:    012345678901234567890123456789012345678901234567890123456789\n"
    "0048:    012345678901234567890123456789012345678901234567890123456789\n"
    "0049:    012345678901234567890123456789012345678901234567890123456789\n"
    "0050:    012345678901234567890123456789012345678901234567890123456789\n"
    "0051:    012345678901234567890123456789012345678901234567890123456789\n"
    "0052:    012345678901234567890123456789012345678901234567890123456789\n"
    "0053:    012345678901234567890123456789012345678901234567890123456789\n"
    "0054:    012345678901234567890123456789012345678901234567890123456789\n"
    "0055:    012345678901234567890123456789012345678901234567890123456789\n"
    "0056:    012345678901234567890123456789012345678901234567890123456789\n"
    "0057:    012345678901234567890123456789012345678901234567890123456789\n"
    "0058:    012345678901234567890123456789012345678901234567890123456789\n"
    "0059:    012345678901234567890123456789012345678901234567890123456789\n"
    "0060:    012345678901234567890123456789012345678901234567890123456789\n"
    "0061:    012345678901234567890123456789012345678901234567890123456789\n"
    "0062:    012345678901234567890123456789012345678901234567890123456789\n"
    "0063:    012345678901234567890123456789012345678901234567890123456789\n"
    "0064:    012345678901234567890123456789012345678901234567890123456789\n"
    "0065:    012345678901234567890123456789012345678901234567890123456789\n"
    "0066:    012345678901234567890123456789012345678901234567890123456789\n"
    "0067:    012345678901234567890123456789012345678901234567890123456789\n"
    "0068:    012345678901234567890123456789012345678901234567890123456789\n"
    "0069:    012345678901234567890123456789012345678901234567890123456789\n"
    "0070:    012345678901234567890123456789012345678901234567890123456789\n"
    FOOTER
  );
}

void handleNotFound(){
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET)?"GET":"POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i=0; i<server.args(); i++){
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}

void setup(void){
  int counter = 60;

  Serial.begin(115200);
  Serial.println("connecting to AP");

  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (counter && (WiFi.status() != WL_CONNECTED)) {
    delay(500);
    Serial.print(".");
    counter--;
  }

  if (!counter) {
    Serial.println("");
    Serial.println("Failed to connect, rebooting");
    ESP.restart();
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp32")) {
    Serial.println("MDNS responder started");
  }

  server.on("/",           handleRoot);
  server.on("/big.html",   handleBig);
  server.on("/small.html", handleSmall);

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
}

void loop(void){
  server.handleClient();
}

The SmallFile loads completely, but BigFile stops after:

0090: 012345678901234567890123456789012345678901234567890123456789
0091: 012345678901234567890123456789012345678901234567890123456789
0092: 012345678

the browser still waits for more (spinning hourglass), because ContentLength was sent correctly.

bbx10 commented

@everslick Thanks for the test program. I found the problem is in WiFiClient.cpp. Can you try this fix on my clone?

https://github.com/bbx10/arduino-esp32/tree/partial_send

If it works, I will submit a PR the arduino-esp32 folks. On my end, it works for your test program and the SDWebServer example.

Your fix also works for me AFAICS. In the short test case as well in the real target code.

Thank you very much!

bbx10 commented

Thanks, I hope arduino-esp32 merges the patch soon because it the bug might cause problems in other libraries.

seems as this works as advertised, so i'm closing the issue.