Skip to content

Commit 41a0e2f

Browse files
committed
Remove usage of Arduino constant emptyString and use our own instead
1 parent a2d5b48 commit 41a0e2f

10 files changed

Lines changed: 55 additions & 47 deletions

File tree

examples/ChunkRetryResponse/ChunkRetryResponse.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void setup() {
177177
memcpy(buffer, answer.c_str(), answer.length());
178178

179179
// finish!
180-
triggerUART = emptyString;
180+
triggerUART = asyncsrv::emptyString;
181181
key = -1;
182182

183183
return answer.length();
@@ -218,6 +218,6 @@ void loop() {
218218
key = Serial.read();
219219
Serial.flush();
220220
// async_ws_log_d("UART input: %c", key);
221-
triggerUART = emptyString;
221+
triggerUART = asyncsrv::emptyString;
222222
}
223223
}

examples/RequestContinuation/RequestContinuation.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void loop() {
8383
Serial.setTimeout(10000);
8484
String response = Serial.readStringUntil('\n'); // waits for a key to be pressed
8585
Serial.println();
86-
message = emptyString;
86+
message = asyncsrv::emptyString;
8787
if (auto request = serialRequest.lock()) {
8888
request->send(200, "text/plain", "Answer: " + response);
8989
}

examples/Templates/Templates.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void setup() {
8484
if (var == "USER") {
8585
return String("Bob ") + millis();
8686
}
87-
return emptyString;
87+
return asyncsrv::emptyString;
8888
});
8989

9090
// Serve a static template with a template processor
@@ -100,7 +100,7 @@ void setup() {
100100
if (var == "USER") {
101101
return "Bob";
102102
}
103-
return emptyString;
103+
return asyncsrv::emptyString;
104104
})
105105
.setLastModified("Sun, 28 Sep 2025 01:02:03 GMT");
106106

@@ -115,7 +115,7 @@ void setup() {
115115
if (var == "USER") {
116116
return String("Bob ") + uptimeInMinutes + " minutes";
117117
}
118-
return emptyString;
118+
return asyncsrv::emptyString;
119119
});
120120

121121
// Serve a template with dynamic content based on user request
@@ -132,7 +132,7 @@ void setup() {
132132
return param->value();
133133
}
134134
}
135-
return emptyString;
135+
return asyncsrv::emptyString;
136136
});
137137
});
138138

src/AsyncEventSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static String generateEventMessage(const char *message, const char *event, uint3
2727

2828
if (!str.reserve(len)) {
2929
async_ws_log_e("Failed to allocate");
30-
return emptyString;
30+
return asyncsrv::emptyString;
3131
}
3232

3333
if (reconnect) {

src/ESPAsyncWebServer.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -670,15 +670,17 @@ class AsyncWebServerRequest {
670670

671671
AsyncWebServerResponse *
672672
beginResponse(FS &fs, const String &path, const char *contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr);
673-
AsyncWebServerResponse *
674-
beginResponse(FS &fs, const String &path, const String &contentType = emptyString, bool download = false, AwsTemplateProcessor callback = nullptr) {
673+
AsyncWebServerResponse *beginResponse(
674+
FS &fs, const String &path, const String &contentType = asyncsrv::emptyString, bool download = false, AwsTemplateProcessor callback = nullptr
675+
) {
675676
return beginResponse(fs, path, contentType.c_str(), download, callback);
676677
}
677678

678679
AsyncWebServerResponse *
679680
beginResponse(File content, const String &path, const char *contentType = asyncsrv::empty, bool download = false, AwsTemplateProcessor callback = nullptr);
680-
AsyncWebServerResponse *
681-
beginResponse(File content, const String &path, const String &contentType = emptyString, bool download = false, AwsTemplateProcessor callback = nullptr) {
681+
AsyncWebServerResponse *beginResponse(
682+
File content, const String &path, const String &contentType = asyncsrv::emptyString, bool download = false, AwsTemplateProcessor callback = nullptr
683+
) {
682684
return beginResponse(content, path, contentType.c_str(), download, callback);
683685
}
684686

@@ -783,11 +785,11 @@ class AsyncWebServerRequest {
783785
#endif
784786
const String &arg(size_t i) const; // get request argument value by number
785787
const String &arg(int i) const {
786-
return i < 0 ? emptyString : arg((size_t)i);
788+
return i < 0 ? asyncsrv::emptyString : arg((size_t)i);
787789
};
788790
const String &argName(size_t i) const; // get request argument name by number
789791
const String &argName(int i) const {
790-
return i < 0 ? emptyString : argName((size_t)i);
792+
return i < 0 ? asyncsrv::emptyString : argName((size_t)i);
791793
};
792794
bool hasArg(const char *name) const; // check if argument exists
793795
bool hasArg(const String &name) const {
@@ -800,14 +802,14 @@ class AsyncWebServerRequest {
800802
#ifdef ASYNCWEBSERVER_REGEX
801803
const String &pathArg(size_t i) const {
802804
if (i >= _pathParams.size()) {
803-
return emptyString;
805+
return asyncsrv::emptyString;
804806
}
805807
auto it = _pathParams.begin();
806808
std::advance(it, i);
807809
return *it;
808810
}
809811
const String &pathArg(int i) const {
810-
return i < 0 ? emptyString : pathArg((size_t)i);
812+
return i < 0 ? asyncsrv::emptyString : pathArg((size_t)i);
811813
}
812814
#else
813815
const String &pathArg(size_t i) const __attribute__((error("ERR: pathArg() requires -D ASYNCWEBSERVER_REGEX and only works on regex handlers")));
@@ -826,11 +828,11 @@ class AsyncWebServerRequest {
826828

827829
const String &header(size_t i) const; // get request header value by number
828830
const String &header(int i) const {
829-
return i < 0 ? emptyString : header((size_t)i);
831+
return i < 0 ? asyncsrv::emptyString : header((size_t)i);
830832
};
831833
const String &headerName(size_t i) const; // get request header name by number
832834
const String &headerName(int i) const {
833-
return i < 0 ? emptyString : headerName((size_t)i);
835+
return i < 0 ? asyncsrv::emptyString : headerName((size_t)i);
834836
};
835837

836838
size_t headers() const; // get header count
@@ -888,7 +890,7 @@ class AsyncWebServerRequest {
888890
_attributes[name] = value;
889891
}
890892
void setAttribute(const char *name, bool value) {
891-
_attributes[name] = value ? "1" : emptyString;
893+
_attributes[name] = value ? "1" : asyncsrv::emptyString;
892894
}
893895
void setAttribute(const char *name, long value) {
894896
_attributes[name] = String(value);
@@ -904,7 +906,7 @@ class AsyncWebServerRequest {
904906
return _attributes.find(name) != _attributes.end();
905907
}
906908

907-
const String &getAttribute(const char *name, const String &defaultValue = emptyString) const;
909+
const String &getAttribute(const char *name, const String &defaultValue = asyncsrv::emptyString) const;
908910
bool getAttribute(const char *name, bool defaultValue) const;
909911
long getAttribute(const char *name, long defaultValue) const;
910912
float getAttribute(const char *name, float defaultValue) const;

src/WebAuthentication.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ bool checkBasicAuthentication(const char *hash, const char *username, const char
2626

2727
String generateBasicHash(const char *username, const char *password) {
2828
if (username == NULL || password == NULL) {
29-
return emptyString;
29+
return asyncsrv::emptyString;
3030
}
3131

3232
size_t toencodeLen = strlen(username) + strlen(password) + 1;
3333

3434
char *toencode = new char[toencodeLen + 1];
3535
if (toencode == NULL) {
36-
return emptyString;
36+
return asyncsrv::emptyString;
3737
}
3838
char *encoded = new char[base64_encode_expected_len(toencodeLen) + 1];
3939
if (encoded == NULL) {
4040
delete[] toencode;
41-
return emptyString;
41+
return asyncsrv::emptyString;
4242
}
4343
sprintf_P(toencode, PSTR("%s:%s"), username, password);
4444
if (base64_encode_chars(toencode, toencodeLen, encoded) > 0) {
@@ -49,7 +49,7 @@ String generateBasicHash(const char *username, const char *password) {
4949
}
5050
delete[] toencode;
5151
delete[] encoded;
52-
return emptyString;
52+
return asyncsrv::emptyString;
5353
}
5454

5555
static bool getMD5(uint8_t *data, uint16_t len, char *output) { // 33 bytes or more
@@ -90,7 +90,7 @@ String genRandomMD5() {
9090
char *out = (char *)malloc(33);
9191
if (out == NULL || !getMD5((uint8_t *)(&r), 4, out)) {
9292
async_ws_log_e("Failed to allocate");
93-
return emptyString;
93+
return asyncsrv::emptyString;
9494
}
9595
String res = String(out);
9696
free(out);
@@ -101,7 +101,7 @@ static String stringMD5(const String &in) {
101101
char *out = (char *)malloc(33);
102102
if (out == NULL || !getMD5((uint8_t *)(in.c_str()), in.length(), out)) {
103103
async_ws_log_e("Failed to allocate");
104-
return emptyString;
104+
return asyncsrv::emptyString;
105105
}
106106
String res = String(out);
107107
free(out);
@@ -110,19 +110,19 @@ static String stringMD5(const String &in) {
110110

111111
String generateDigestHash(const char *username, const char *password, const char *realm) {
112112
if (username == NULL || password == NULL || realm == NULL) {
113-
return emptyString;
113+
return asyncsrv::emptyString;
114114
}
115115
char *out = (char *)malloc(33);
116116
if (out == NULL) {
117117
async_ws_log_e("Failed to allocate");
118-
return emptyString;
118+
return asyncsrv::emptyString;
119119
}
120120

121121
String in;
122122
if (!in.reserve(strlen(username) + strlen(realm) + strlen(password) + 2)) {
123123
async_ws_log_e("Failed to allocate");
124124
free(out);
125-
return emptyString;
125+
return asyncsrv::emptyString;
126126
}
127127

128128
in.concat(username);
@@ -134,7 +134,7 @@ String generateDigestHash(const char *username, const char *password, const char
134134
if (!getMD5((uint8_t *)(in.c_str()), in.length(), out)) {
135135
async_ws_log_e("Failed to allocate");
136136
free(out);
137-
return emptyString;
137+
return asyncsrv::emptyString;
138138
}
139139

140140
in = String(out);

src/WebHandlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request) {
260260
request->_tempFile.close();
261261
response = new AsyncBasicResponse(304); // Not modified
262262
} else {
263-
response = new AsyncFileResponse(request->_tempFile, filename, emptyString, false, _callback);
263+
response = new AsyncFileResponse(request->_tempFile, filename, asyncsrv::emptyString, false, _callback);
264264
}
265265

266266
if (!response) {

src/WebRequest.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ void AsyncWebServerRequest::_addGetParams(const String &params) {
298298
equal = end;
299299
}
300300
String name = urlDecode(params.substring(start, equal));
301-
String value = urlDecode(equal + 1 < end ? params.substring(equal + 1, end) : emptyString);
301+
String value = urlDecode(equal + 1 < end ? params.substring(equal + 1, end) : asyncsrv::emptyString);
302302
if (name.length()) {
303303
_params.emplace_back(name, value);
304304
}
@@ -336,7 +336,7 @@ bool AsyncWebServerRequest::_parseReqHead() {
336336
_version = 1;
337337
}
338338

339-
_temp = emptyString;
339+
_temp = asyncsrv::emptyString;
340340
return true;
341341
}
342342

@@ -545,7 +545,7 @@ bool AsyncWebServerRequest::_parseReqHeader() {
545545
}
546546
#if defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) || defined(LIBRETINY)
547547
// Ancient PRI core does not have String::clear() method 8-()
548-
_temp = emptyString;
548+
_temp = asyncsrv::emptyString;
549549
#else
550550
_temp.clear();
551551
#endif
@@ -570,7 +570,7 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data) {
570570

571571
#if defined(TARGET_RP2040) || defined(TARGET_RP2350) || defined(PICO_RP2040) || defined(PICO_RP2350) || defined(LIBRETINY)
572572
// Ancient PRI core does not have String::clear() method 8-()
573-
_temp = emptyString;
573+
_temp = asyncsrv::emptyString;
574574
#else
575575
_temp.clear();
576576
#endif
@@ -615,10 +615,10 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) {
615615

616616
if (!_parsedLength) {
617617
_multiParseState = EXPECT_BOUNDARY;
618-
_temp = emptyString;
619-
_itemName = emptyString;
620-
_itemFilename = emptyString;
621-
_itemType = emptyString;
618+
_temp = asyncsrv::emptyString;
619+
_itemName = asyncsrv::emptyString;
620+
_itemFilename = asyncsrv::emptyString;
621+
_itemType = asyncsrv::emptyString;
622622
}
623623

624624
if (_multiParseState == WAIT_FOR_RETURN1) {
@@ -686,13 +686,13 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) {
686686
_params.emplace_back(T_filename, _itemFilename, true, true);
687687
}
688688
}
689-
_temp = emptyString;
689+
_temp = asyncsrv::emptyString;
690690
} else {
691691
_multiParseState = WAIT_FOR_RETURN1;
692692
// value starts from here
693693
_itemSize = 0;
694694
_itemStartIndex = _parsedLength;
695-
_itemValue = emptyString;
695+
_itemValue = asyncsrv::emptyString;
696696
if (_itemIsFile) {
697697
if (_itemBuffer) {
698698
free(_itemBuffer);
@@ -1219,7 +1219,7 @@ const String &AsyncWebServerRequest::arg(const char *name) const {
12191219
return arg.value();
12201220
}
12211221
}
1222-
return emptyString;
1222+
return asyncsrv::emptyString;
12231223
}
12241224

12251225
#ifdef ESP8266
@@ -1238,7 +1238,7 @@ const String &AsyncWebServerRequest::argName(size_t i) const {
12381238

12391239
const String &AsyncWebServerRequest::header(const char *name) const {
12401240
const AsyncWebHeader *h = getHeader(name);
1241-
return h ? h->value() : emptyString;
1241+
return h ? h->value() : asyncsrv::emptyString;
12421242
}
12431243

12441244
#ifdef ESP8266
@@ -1249,12 +1249,12 @@ const String &AsyncWebServerRequest::header(const __FlashStringHelper *data) con
12491249

12501250
const String &AsyncWebServerRequest::header(size_t i) const {
12511251
const AsyncWebHeader *h = getHeader(i);
1252-
return h ? h->value() : emptyString;
1252+
return h ? h->value() : asyncsrv::emptyString;
12531253
}
12541254

12551255
const String &AsyncWebServerRequest::headerName(size_t i) const {
12561256
const AsyncWebHeader *h = getHeader(i);
1257-
return h ? h->name() : emptyString;
1257+
return h ? h->name() : asyncsrv::emptyString;
12581258
}
12591259

12601260
String AsyncWebServerRequest::urlDecode(const String &text) const {
@@ -1265,7 +1265,7 @@ String AsyncWebServerRequest::urlDecode(const String &text) const {
12651265
// Allocate the string internal buffer - never longer from source text
12661266
if (!decoded.reserve(len)) {
12671267
async_ws_log_e("Failed to allocate");
1268-
return emptyString;
1268+
return asyncsrv::emptyString;
12691269
}
12701270
while (i < len) {
12711271
char decodedChar;

src/WebResponseImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AsyncBasicResponse : public AsyncWebServerResponse {
3737

3838
public:
3939
explicit AsyncBasicResponse(int code, const char *contentType = asyncsrv::empty, const char *content = asyncsrv::empty);
40-
AsyncBasicResponse(int code, const String &contentType, const String &content = emptyString)
40+
AsyncBasicResponse(int code, const String &contentType, const String &content = asyncsrv::emptyString)
4141
: AsyncBasicResponse(code, contentType.c_str(), content.c_str()) {}
4242
void _respond(AsyncWebServerRequest *request) final;
4343
size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time) final {

src/literals.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424

2525
namespace asyncsrv {
2626

27+
#ifdef ARDUINO
28+
using ::emptyString;
29+
#else
30+
inline const String emptyString{};
31+
#endif
32+
2733
static constexpr const char empty[] = "";
2834

2935
static constexpr const char T__opaque[] = "\", opaque=\"";

0 commit comments

Comments
 (0)