Add cache for the editor

Idea from:
http://tinkerman.cat/embed-your-website-in-your-esp8266-firmware-image/
This commit is contained in:
me-no-dev
2017-09-12 23:30:11 +03:00
parent 4895f973e8
commit b681dbc3cd

View File

@@ -361,6 +361,7 @@ bool SPIFFSEditor::canHandle(AsyncWebServerRequest *request){
if(!request->_tempFile) if(!request->_tempFile)
return false; return false;
} }
request->addInterestingHeader("If-Modified-Since");
return true; return true;
} }
else if(request->method() == HTTP_POST) else if(request->method() == HTTP_POST)
@@ -419,10 +420,16 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request){
request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download")); request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download"));
} }
else { else {
const char * buildTime = __DATE__ " " __TIME__ " GMT";
if (request->header("If-Modified-Since").equals(buildTime)) {
request->send(304);
} else {
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", edit_htm_gz, edit_htm_gz_len); AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", edit_htm_gz, edit_htm_gz_len);
response->addHeader("Content-Encoding", "gzip"); response->addHeader("Content-Encoding", "gzip");
response->addHeader("Last-Modified", buildTime);
request->send(response); request->send(response);
} }
}
} else if(request->method() == HTTP_DELETE){ } else if(request->method() == HTTP_DELETE){
if(request->hasParam("path", true)){ if(request->hasParam("path", true)){
_fs.remove(request->getParam("path", true)->value()); _fs.remove(request->getParam("path", true)->value());