feat: ability to use compressed files for StaticPage

This commit is contained in:
Yurii
2024-04-12 04:08:28 +03:00
parent a026a962f0
commit 6bb261dfd7

View File

@@ -1,4 +1,7 @@
#include <FS.h> #include <FS.h>
#include <detail/mimetable.h>
using namespace mime;
class StaticPage : public RequestHandler { class StaticPage : public RequestHandler {
public: public:
@@ -61,6 +64,14 @@ public:
} }
#endif #endif
if (!this->path.endsWith(FPSTR(mimeTable[gz].endsWith)) && !this->fs->exists(path)) {
String pathWithGz = this->path + FPSTR(mimeTable[gz].endsWith);
if (this->fs->exists(pathWithGz)) {
this->path += FPSTR(mimeTable[gz].endsWith);
}
}
File file = this->fs->open(this->path, "r"); File file = this->fs->open(this->path, "r");
if (!file) { if (!file) {
return false; return false;
@@ -93,6 +104,6 @@ protected:
BeforeSendCallback beforeSendCallback; BeforeSendCallback beforeSendCallback;
String eTag; String eTag;
const char* uri = nullptr; const char* uri = nullptr;
const char* path = nullptr; String path;
const char* cacheHeader = nullptr; const char* cacheHeader = nullptr;
}; };