1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Add LittleFS support to ESP8266WebServer.serveStatic() (#6987)

* Remove trailing whitespace

* Improve "is file" check for LittleFS support

The previous implementation was based on a quirk of SPIFFS (that exists
returns false for directories) so it wouldn't work with LittleFS. This
implementation works with both.

Co-authored-by: Develo <deveyes@gmail.com>
This commit is contained in:
JasperHorn 2020-01-05 05:33:05 +01:00 committed by Earle F. Philhower, III
parent d4d89244bd
commit 8242d72271

View File

@ -70,7 +70,15 @@ public:
, _path(path) , _path(path)
, _cache_header(cache_header) , _cache_header(cache_header)
{ {
_isFile = fs.exists(path); if (fs.exists(path)) {
File file = fs.open(path, "r");
_isFile = file && file.isFile();
file.close();
}
else {
_isFile = false;
}
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header); DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
_baseUriLength = _uri.length(); _baseUriLength = _uri.length();
} }