mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-07-31 11:17:31 +02:00
Fix AsyncStaticWebHandler to remove the wrong gzip stat feature which is not taking in consideration the frequency of each request. Expose instead a boolean flag to let the user control that.
This commit is contained in:
@ -47,13 +47,13 @@ class AsyncStaticWebHandler : public AsyncWebHandler {
|
||||
String _last_modified;
|
||||
AwsTemplateProcessor _callback;
|
||||
bool _isDir;
|
||||
bool _gzipFirst;
|
||||
uint8_t _gzipStats;
|
||||
bool _tryGzipFirst = true;
|
||||
|
||||
public:
|
||||
AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control);
|
||||
virtual bool canHandle(AsyncWebServerRequest* request) const override final;
|
||||
virtual void handleRequest(AsyncWebServerRequest* request) override final;
|
||||
AsyncStaticWebHandler& setTryGzipFirst(bool value);
|
||||
AsyncStaticWebHandler& setIsDir(bool isDir);
|
||||
AsyncStaticWebHandler& setDefaultFile(const char* filename);
|
||||
AsyncStaticWebHandler& setCacheControl(const char* cache_control);
|
||||
|
@ -56,10 +56,11 @@ AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, FS& fs, const char
|
||||
_uri = _uri.substring(0, _uri.length() - 1);
|
||||
if (_path[_path.length() - 1] == '/')
|
||||
_path = _path.substring(0, _path.length() - 1);
|
||||
}
|
||||
|
||||
// Reset stats
|
||||
_gzipFirst = false;
|
||||
_gzipStats = 0xF8;
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setTryGzipFirst(bool value) {
|
||||
_tryGzipFirst = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
AsyncStaticWebHandler& AsyncStaticWebHandler::setIsDir(bool isDir) {
|
||||
@ -148,7 +149,7 @@ bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest* request, const St
|
||||
|
||||
String gzip = path + T__gz;
|
||||
|
||||
if (_gzipFirst) {
|
||||
if (_tryGzipFirst) {
|
||||
if (_fs.exists(gzip)) {
|
||||
request->_tempFile = _fs.open(gzip, fs::FileOpenMode::read);
|
||||
gzipFound = FILE_IS_REAL(request->_tempFile);
|
||||
@ -180,15 +181,6 @@ bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest* request, const St
|
||||
char* _tempPath = (char*)malloc(pathLen + 1);
|
||||
snprintf_P(_tempPath, pathLen + 1, PSTR("%s"), path.c_str());
|
||||
request->_tempObject = (void*)_tempPath;
|
||||
|
||||
// Calculate gzip statistic
|
||||
_gzipStats = (_gzipStats << 1) + (gzipFound ? 1 : 0);
|
||||
if (_gzipStats == 0x00)
|
||||
_gzipFirst = false; // All files are not gzip
|
||||
else if (_gzipStats == 0xFF)
|
||||
_gzipFirst = true; // All files are gzip
|
||||
else
|
||||
_gzipFirst = _countBits(_gzipStats) > 4; // IF we have more gzip files - try gzip first
|
||||
}
|
||||
|
||||
return found;
|
||||
|
Reference in New Issue
Block a user