Skip to content

Commit 8242d72

Browse files
JasperHorndevyte
authored andcommitted
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>
1 parent d4d8924 commit 8242d72

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
7070
, _path(path)
7171
, _cache_header(cache_header)
7272
{
73-
_isFile = fs.exists(path);
73+
if (fs.exists(path)) {
74+
File file = fs.open(path, "r");
75+
_isFile = file && file.isFile();
76+
file.close();
77+
}
78+
else {
79+
_isFile = false;
80+
}
81+
7482
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
7583
_baseUriLength = _uri.length();
7684
}
@@ -96,7 +104,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
96104
if (!_isFile) {
97105
// Base URI doesn't point to a file.
98106
// If a directory is requested, look for index file.
99-
if (requestUri.endsWith("/"))
107+
if (requestUri.endsWith("/"))
100108
requestUri += "index.htm";
101109

102110
// Append whatever follows this URI in request to get the file path.

0 commit comments

Comments
 (0)