mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-02 14:50:39 +08:00
Use new chunked feature
this feature give an average gain of +65% of speed for dynamic pages
This commit is contained in:
parent
2ac89dc6a7
commit
b1456df090
@ -345,13 +345,8 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST
|
||||
|
||||
LinkedList<File> myFileList = LinkedList<File>();
|
||||
String buffer2send;
|
||||
String bufferheader(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "));
|
||||
int size_content=0;
|
||||
bool header_sent=false;
|
||||
|
||||
//one loop to calculate size + one loop to really send
|
||||
//size_content is a mandatory element to avoid memory leak
|
||||
for(int processing_step=0; processing_step<2; processing_step++) {
|
||||
buffer2send="";
|
||||
//open template file
|
||||
File currentfile = SPIFFS.open(filename, "r");
|
||||
@ -471,21 +466,17 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST
|
||||
buffer2send+=sLine;
|
||||
//if buffer limit is reached
|
||||
if (buffer2send.length()>1200) {
|
||||
//if we are just doing size calculation
|
||||
if (processing_step==0) {
|
||||
//add buffer size
|
||||
size_content+=buffer2send.length();
|
||||
} else { //if no size calculation, send data
|
||||
//if header is not send yet
|
||||
if (!header_sent) {
|
||||
//send header with calculated size
|
||||
header_sent=true;
|
||||
web_interface->WebServer.sendContent(bufferheader);
|
||||
|
||||
web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
web_interface->WebServer.send(200);
|
||||
web_interface->WebServer.sendHeader("Content-Type","text/html");
|
||||
web_interface->WebServer.sendHeader("Cache-Control","no-cache");
|
||||
}
|
||||
//send data
|
||||
web_interface->WebServer.sendContent(buffer2send);
|
||||
}
|
||||
//reset buffer
|
||||
buffer2send="";
|
||||
}
|
||||
@ -511,28 +502,19 @@ bool processTemplate(const char * filename, STORESTRINGS_CLASS & KeysList , ST
|
||||
}
|
||||
//check if something is still in buffer and need to be send
|
||||
if (buffer2send!="") {
|
||||
//if we are doing size calculation
|
||||
if (processing_step==0) {
|
||||
//add buffer size
|
||||
size_content+=buffer2send.length();
|
||||
} else { //if no size calculation, send data
|
||||
//if header is not send yet
|
||||
if (!header_sent) {
|
||||
//send header with calculated size
|
||||
web_interface->WebServer.sendContent(bufferheader);
|
||||
//send header
|
||||
web_interface->WebServer.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
web_interface->WebServer.send(200);
|
||||
web_interface->WebServer.sendHeader("Content-Type","text/html");
|
||||
web_interface->WebServer.sendHeader("Cache-Control","no-cache");
|
||||
}
|
||||
//send data
|
||||
web_interface->WebServer.sendContent(buffer2send);
|
||||
|
||||
}
|
||||
}
|
||||
//if we end size calculation loop
|
||||
if (processing_step==0) {
|
||||
//let's build the header with correct size'
|
||||
bufferheader.concat(size_content);
|
||||
bufferheader.concat(F("\r\nConnection: close\r\nAccess-Control-Allow-Origin: *\r\n\r\n"));
|
||||
}
|
||||
}
|
||||
//close line
|
||||
web_interface->WebServer.sendContent("");
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user