diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 535e387a4..d60b730cb 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -37,6 +37,14 @@ #error Platform not supported #endif +#if defined(FS_NO_GLOBALS) +#define SPFS fs::FS +#define SPFILE fs::File +#else +#define SPFS FS +#define SPFILE File +#endif + #define DEBUGF(...) //Serial.printf(__VA_ARGS__) @@ -177,7 +185,7 @@ class AsyncWebServerRequest { void _handleUploadEnd(); public: - File _tempFile; + SPFILE _tempFile; void *_tempObject; AsyncWebServerRequest(AsyncWebServer*, AsyncClient*); @@ -208,8 +216,8 @@ class AsyncWebServerRequest { void send(AsyncWebServerResponse *response); void send(int code, const String& contentType=String(), const String& content=String()); - void send(FS &fs, const String& path, const String& contentType=String(), bool download=false); - void send(File content, const String& path, const String& contentType=String(), bool download=false); + void send(SPFS &fs, const String& path, const String& contentType=String(), bool download=false); + void send(SPFILE content, const String& path, const String& contentType=String(), bool download=false); void send(Stream &stream, const String& contentType, size_t len); void send(const String& contentType, size_t len, AwsResponseFiller callback); void sendChunked(const String& contentType, AwsResponseFiller callback); @@ -217,8 +225,8 @@ class AsyncWebServerRequest { void send_P(int code, const String& contentType, PGM_P content); AsyncWebServerResponse *beginResponse(int code, const String& contentType=String(), const String& content=String()); - AsyncWebServerResponse *beginResponse(FS &fs, const String& path, const String& contentType=String(), bool download=false); - AsyncWebServerResponse *beginResponse(File content, const String& path, const String& contentType=String(), bool download=false); + AsyncWebServerResponse *beginResponse(SPFS &fs, const String& path, const String& contentType=String(), bool download=false); + AsyncWebServerResponse *beginResponse(SPFILE content, const String& path, const String& contentType=String(), bool download=false); AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len); AsyncWebServerResponse *beginResponse(const String& contentType, size_t len, AwsResponseFiller callback); AsyncWebServerResponse *beginChunkedResponse(const String& contentType, AwsResponseFiller callback); @@ -380,7 +388,7 @@ class AsyncWebServer { AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload); AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody); - AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL); + AsyncStaticWebHandler& serveStatic(const char* uri, SPFS& fs, const char* path, const char* cache_control = NULL); void onNotFound(ArRequestHandlerFunction fn); //called when handler is not assigned void onFileUpload(ArUploadHandlerFunction fn); //handle file uploads diff --git a/src/WebHandlerImpl.h b/src/WebHandlerImpl.h index 58e6b822b..07caf04ae 100644 --- a/src/WebHandlerImpl.h +++ b/src/WebHandlerImpl.h @@ -31,7 +31,7 @@ class AsyncStaticWebHandler: public AsyncWebHandler { bool _fileExists(AsyncWebServerRequest *request, const String& path); uint8_t _countBits(const uint8_t value) const; protected: - FS _fs; + SPFS _fs; String _uri; String _path; String _default_file; @@ -41,7 +41,7 @@ class AsyncStaticWebHandler: public AsyncWebHandler { bool _gzipFirst; uint8_t _gzipStats; public: - AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control); + AsyncStaticWebHandler(const char* uri, SPFS& fs, const char* path, const char* cache_control); virtual bool canHandle(AsyncWebServerRequest *request) override final; virtual void handleRequest(AsyncWebServerRequest *request) override final; AsyncStaticWebHandler& setIsDir(bool isDir); diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index 74eed419f..ecffd9bf1 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -597,13 +597,13 @@ AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const St return new AsyncBasicResponse(code, contentType, content); } -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(FS &fs, const String& path, const String& contentType, bool download){ +AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(SPFS &fs, const String& path, const String& contentType, bool download){ if(fs.exists(path) || (!download && fs.exists(path+".gz"))) return new AsyncFileResponse(fs, path, contentType, download); return NULL; } -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(File content, const String& path, const String& contentType, bool download){ +AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(SPFILE content, const String& path, const String& contentType, bool download){ if(content == true) return new AsyncFileResponse(content, path, contentType, download); return NULL; @@ -639,13 +639,13 @@ void AsyncWebServerRequest::send(int code, const String& contentType, const Stri send(beginResponse(code, contentType, content)); } -void AsyncWebServerRequest::send(FS &fs, const String& path, const String& contentType, bool download){ +void AsyncWebServerRequest::send(SPFS &fs, const String& path, const String& contentType, bool download){ if(fs.exists(path) || (!download && fs.exists(path+".gz"))){ send(beginResponse(fs, path, contentType, download)); } else send(404); } -void AsyncWebServerRequest::send(File content, const String& path, const String& contentType, bool download){ +void AsyncWebServerRequest::send(SPFILE content, const String& path, const String& contentType, bool download){ if(content == true){ send(beginResponse(content, path, contentType, download)); } else send(404); diff --git a/src/WebResponseImpl.h b/src/WebResponseImpl.h index e0f4403db..7c37dabf9 100644 --- a/src/WebResponseImpl.h +++ b/src/WebResponseImpl.h @@ -43,12 +43,12 @@ class AsyncAbstractResponse: public AsyncWebServerResponse { class AsyncFileResponse: public AsyncAbstractResponse { private: - File _content; + SPFILE _content; String _path; void _setContentType(const String& path); public: - AsyncFileResponse(FS &fs, const String& path, const String& contentType=String(), bool download=false); - AsyncFileResponse(File content, const String& path, const String& contentType=String(), bool download=false); + AsyncFileResponse(SPFS &fs, const String& path, const String& contentType=String(), bool download=false); + AsyncFileResponse(SPFILE content, const String& path, const String& contentType=String(), bool download=false); ~AsyncFileResponse(); bool _sourceValid() const { return !!(_content); } virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; diff --git a/src/WebResponses.cpp b/src/WebResponses.cpp index c0f60c858..37d8282b5 100644 --- a/src/WebResponses.cpp +++ b/src/WebResponses.cpp @@ -352,7 +352,7 @@ void AsyncFileResponse::_setContentType(const String& path){ else _contentType = "text/plain"; } -AsyncFileResponse::AsyncFileResponse(FS &fs, const String& path, const String& contentType, bool download){ +AsyncFileResponse::AsyncFileResponse(SPFS &fs, const String& path, const String& contentType, bool download){ _code = 200; _path = path; diff --git a/src/WebServer.cpp b/src/WebServer.cpp index f2538e81b..dce345200 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -156,7 +156,7 @@ AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, ArRequestHandlerFun return *handler; } -AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control){ +AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, SPFS& fs, const char* path, const char* cache_control){ AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control); addHandler(handler); return *handler;