Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

added preliminary 'FS_NO_GLOBALS' support #112

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/ESPAsyncWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down Expand Up @@ -177,7 +185,7 @@ class AsyncWebServerRequest {
void _handleUploadEnd();

public:
File _tempFile;
SPFILE _tempFile;
void *_tempObject;

AsyncWebServerRequest(AsyncWebServer*, AsyncClient*);
Expand Down Expand Up @@ -208,17 +216,17 @@ 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);
void send_P(int code, const String& contentType, const uint8_t * content, size_t len);
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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/WebHandlerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/WebRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/WebResponseImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/WebResponses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down