mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
refactor: improved web cache
This commit is contained in:
@@ -218,7 +218,6 @@ protected:
|
||||
CanHandleCallback canHandleCallback;
|
||||
BeforeSendCallback beforeSendCallback;
|
||||
TemplateCallback templateCallback;
|
||||
String eTag;
|
||||
const char* uri = nullptr;
|
||||
const char* path = nullptr;
|
||||
const char* cacheHeader = nullptr;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include <FS.h>
|
||||
#include <detail/mimetable.h>
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#include <detail/RequestHandlersImpl.h>
|
||||
#endif
|
||||
|
||||
using namespace mime;
|
||||
|
||||
@@ -47,21 +50,25 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
if (server._eTagEnabled) {
|
||||
if (server._eTagFunction) {
|
||||
this->eTag = (server._eTagFunction)(*this->fs, this->path);
|
||||
if (this->eTag.isEmpty()) {
|
||||
if (server._eTagFunction) {
|
||||
this->eTag = (server._eTagFunction)(*this->fs, this->path);
|
||||
|
||||
} else if (this->eTag.isEmpty()) {
|
||||
this->eTag = esp8266webserver::calcETag(*this->fs, this->path);
|
||||
} else {
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
this->eTag = esp8266webserver::calcETag(*this->fs, this->path);
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
this->eTag = StaticRequestHandler::calcETag(*this->fs, this->path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (server.header(F("If-None-Match")).equals(this->eTag.c_str())) {
|
||||
if (!this->eTag.isEmpty() && server.header(F("If-None-Match")).equals(this->eTag.c_str())) {
|
||||
server.send(304);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!this->path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !this->fs->exists(path)) {
|
||||
String pathWithGz = this->path + FPSTR(mimeTable[gz].endsWith);
|
||||
@@ -84,11 +91,11 @@ public:
|
||||
server.sendHeader(F("Cache-Control"), this->cacheHeader);
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
if (server._eTagEnabled && this->eTag.length() > 0) {
|
||||
if (server._eTagEnabled && !this->eTag.isEmpty()) {
|
||||
server.sendHeader(F("ETag"), this->eTag);
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
server.streamFile(file, F("text/html"), method);
|
||||
#else
|
||||
server.streamFile(file, F("text/html"), 200);
|
||||
|
||||
Reference in New Issue
Block a user