From 6bb261dfd7cb989bbd12f82076bd224859569e68 Mon Sep 17 00:00:00 2001 From: Yurii Date: Fri, 12 Apr 2024 04:08:28 +0300 Subject: [PATCH] feat: ability to use compressed files for StaticPage --- lib/WebServerHandlers/StaticPage.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/WebServerHandlers/StaticPage.h b/lib/WebServerHandlers/StaticPage.h index 91894ec..0635a02 100644 --- a/lib/WebServerHandlers/StaticPage.h +++ b/lib/WebServerHandlers/StaticPage.h @@ -1,4 +1,7 @@ #include +#include + +using namespace mime; class StaticPage : public RequestHandler { public: @@ -61,6 +64,14 @@ public: } #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"); if (!file) { return false; @@ -93,6 +104,6 @@ protected: BeforeSendCallback beforeSendCallback; String eTag; const char* uri = nullptr; - const char* path = nullptr; + String path; const char* cacheHeader = nullptr; }; \ No newline at end of file