Skip to content

Commit ad1fd1a

Browse files
Merge pull request #120 from ESP32Async/cleanup
Updated serveStatic example
2 parents d64c0b1 + fd60ccb commit ad1fd1a

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

examples/StaticFile/StaticFile.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ void setup() {
105105
f.close();
106106
}
107107

108+
LittleFS.mkdir("/files");
109+
110+
{
111+
File f = LittleFS.open("/files/a.txt", "w");
112+
assert(f);
113+
f.print("Hello from a.txt");
114+
f.close();
115+
}
116+
117+
{
118+
File f = LittleFS.open("/files/b.txt", "w");
119+
assert(f);
120+
f.print("Hello from b.txt");
121+
f.close();
122+
}
123+
108124
// curl -v http://192.168.4.1/
109125
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
110126
request->redirect("/index.html");
@@ -113,6 +129,12 @@ void setup() {
113129
// curl -v http://192.168.4.1/index.html
114130
server.serveStatic("/index.html", LittleFS, "/index.html");
115131

132+
// Example to serve a directory content
133+
// curl -v http://192.168.4.1/base/ => serves a.txt
134+
// curl -v http://192.168.4.1/base/a.txt => serves a.txt
135+
// curl -v http://192.168.4.1/base/b.txt => serves b.txt
136+
server.serveStatic("/base", LittleFS, "/files").setDefaultFile("a.txt");
137+
116138
server.begin();
117139
}
118140

src/WebHandlerImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class AsyncStaticWebHandler : public AsyncWebHandler {
1919
private:
2020
bool _getFile(AsyncWebServerRequest *request) const;
2121
bool _searchFile(AsyncWebServerRequest *request, const String &path);
22-
uint8_t _countBits(const uint8_t value) const;
2322

2423
protected:
2524
FS _fs;

src/WebHandlers.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,6 @@ bool AsyncStaticWebHandler::_searchFile(AsyncWebServerRequest *request, const St
187187
return found;
188188
}
189189

190-
uint8_t AsyncStaticWebHandler::_countBits(const uint8_t value) const {
191-
uint8_t w = value;
192-
uint8_t n;
193-
for (n = 0; w != 0; n++) {
194-
w &= w - 1;
195-
}
196-
return n;
197-
}
198-
199190
void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request) {
200191
// Get the filename from request->_tempObject and free it
201192
String filename((char *)request->_tempObject);

0 commit comments

Comments
 (0)