diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 781fdb0..510fcac 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -295,13 +295,13 @@ class AsyncWebServerRequest { void send(AsyncWebServerResponse* response); - void send(int code, const char* contentType = "", const char* content = "", AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, callback)); } + void send(int code, const char* contentType = asyncsrv::empty, const char* content = asyncsrv::empty, AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, callback)); } void send(int code, const String& contentType, const String& content = emptyString, AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, callback)); } void send(int code, const char* contentType, const uint8_t* content, size_t len, AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, len, callback)); } void send(int code, const String& contentType, const uint8_t* content, size_t len, AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, len, callback)); } - void send(FS& fs, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr) { + void send(FS& fs, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr) { if (fs.exists(path) || (!download && fs.exists(path + asyncsrv::T__gz))) { send(beginResponse(fs, path, contentType, download, callback)); } else @@ -309,7 +309,7 @@ class AsyncWebServerRequest { } void send(FS& fs, const String& path, const String& contentType = emptyString, bool download = false, AwsTemplateProcessor callback = nullptr) { send(fs, path, contentType.c_str(), download, callback); } - void send(File content, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr) { + void send(File content, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr) { if (content) { send(beginResponse(content, path, contentType, download, callback)); } else @@ -339,16 +339,16 @@ class AsyncWebServerRequest { void send(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback = nullptr) { send(beginResponse(code, contentType, content, callback)); } #endif - AsyncWebServerResponse* beginResponse(int code, const char* contentType = "", const char* content = "", AwsTemplateProcessor callback = nullptr); + AsyncWebServerResponse* beginResponse(int code, const char* contentType = asyncsrv::empty, const char* content = asyncsrv::empty, AwsTemplateProcessor callback = nullptr); AsyncWebServerResponse* beginResponse(int code, const String& contentType, const String& content = emptyString, AwsTemplateProcessor callback = nullptr) { return beginResponse(code, contentType.c_str(), content.c_str(), callback); } AsyncWebServerResponse* beginResponse(int code, const char* contentType, const uint8_t* content, size_t len, AwsTemplateProcessor callback = nullptr); AsyncWebServerResponse* beginResponse(int code, const String& contentType, const uint8_t* content, size_t len, AwsTemplateProcessor callback = nullptr) { return beginResponse(code, contentType.c_str(), content, len, callback); } - AsyncWebServerResponse* beginResponse(FS& fs, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr); + AsyncWebServerResponse* beginResponse(FS& fs, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr); AsyncWebServerResponse* beginResponse(FS& fs, const String& path, const String& contentType = emptyString, bool download = false, AwsTemplateProcessor callback = nullptr) { return beginResponse(fs, path, contentType.c_str(), download, callback); } - AsyncWebServerResponse* beginResponse(File content, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr); + AsyncWebServerResponse* beginResponse(File content, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr); AsyncWebServerResponse* beginResponse(File content, const String& path, const String& contentType = emptyString, bool download = false, AwsTemplateProcessor callback = nullptr) { return beginResponse(content, path, contentType.c_str(), download, callback); } AsyncWebServerResponse* beginResponse(Stream& stream, const char* contentType, size_t len, AwsTemplateProcessor callback = nullptr); diff --git a/src/WebResponseImpl.h b/src/WebResponseImpl.h index 21b9044..a6f71bb 100644 --- a/src/WebResponseImpl.h +++ b/src/WebResponseImpl.h @@ -28,6 +28,7 @@ #endif #include #include +#include "literals.h" // It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max. @@ -36,7 +37,7 @@ class AsyncBasicResponse : public AsyncWebServerResponse { String _content; public: - AsyncBasicResponse(int code, const char* contentType = "", const char* content = ""); + explicit AsyncBasicResponse(int code, const char* contentType = asyncsrv::empty, const char* content = asyncsrv::empty); AsyncBasicResponse(int code, const String& contentType, const String& content = emptyString) : AsyncBasicResponse(code, contentType.c_str(), content.c_str()) {} void _respond(AsyncWebServerRequest* request); size_t _ack(AsyncWebServerRequest* request, size_t len, uint32_t time); @@ -80,9 +81,9 @@ class AsyncFileResponse : public AsyncAbstractResponse { void _setContentTypeFromPath(const String& path); public: - AsyncFileResponse(FS& fs, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr); + AsyncFileResponse(FS& fs, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr); AsyncFileResponse(FS& fs, const String& path, const String& contentType, bool download = false, AwsTemplateProcessor callback = nullptr) : AsyncFileResponse(fs, path, contentType.c_str(), download, callback) {} - AsyncFileResponse(File content, const String& path, const char* contentType = "", bool download = false, AwsTemplateProcessor callback = nullptr); + AsyncFileResponse(File content, const String& path, const char* contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr); AsyncFileResponse(File content, const String& path, const String& contentType, bool download = false, AwsTemplateProcessor callack = nullptr) : AsyncFileResponse(content, path, contentType.c_str(), download, callack) {} ~AsyncFileResponse(); bool _sourceValid() const { return !!(_content); } diff --git a/src/literals.h b/src/literals.h index c60a3eb..8a7293b 100644 --- a/src/literals.h +++ b/src/literals.h @@ -2,6 +2,8 @@ namespace asyncsrv { +static constexpr const char* empty = ""; + #ifndef ESP8622 static constexpr const char* T_100_CONTINUE = "100-continue"; static constexpr const char* T_ACCEPT = "Accept";