Skip to content

Commit 76b5ab4

Browse files
Fix HTTP_ANY macro conflict with Arduino core: rename enum to HTTP_ALL, provide HTTP_ANY as backward-compat constexpr
Co-authored-by: mathieucarbou <61346+mathieucarbou@users.noreply.github.com>
1 parent b337f0b commit 76b5ab4

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/ESPAsyncWebServer.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum AsyncWebRequestMethodType {
9797
HTTP_MOVE = 0b0001000000000000,
9898
HTTP_COPY = 0b0010000000000000,
9999
HTTP_RESERVED = 0b0100000000000000,
100-
HTTP_ANY = 0b0111111111111111,
100+
HTTP_ALL = 0b0111111111111111,
101101
};
102102
}; // namespace AsyncWebRequestMethod
103103

@@ -112,6 +112,18 @@ extern constexpr inline WebRequestMethodComposite operator|(WebRequestMethod l,
112112
return static_cast<WebRequestMethodComposite>(l) | r;
113113
};
114114

115+
// HTTP_ANY is commonly defined as a macro in Arduino core HTTP client libraries (e.g., ESP8266 HTTPClient.h).
116+
// Macros are expanded by the preprocessor before C++ namespace resolution, so even a namespace-qualified
117+
// reference like AsyncWebRequestMethod::HTTP_ANY would be incorrectly expanded to AsyncWebRequestMethod::0.
118+
// To avoid this conflict, HTTP_ANY is provided here as a C++ constexpr (not a macro), after undefining
119+
// any previously defined HTTP_ANY macro. Use HTTP_ALL as the canonical non-conflicting name.
120+
#ifdef HTTP_ANY
121+
#undef HTTP_ANY
122+
#endif
123+
namespace AsyncWebRequestMethod {
124+
static constexpr AsyncWebRequestMethodType HTTP_ANY = HTTP_ALL;
125+
} // namespace AsyncWebRequestMethod
126+
115127
#if !defined(ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODS)
116128
// Import the method enum values to the global namespace
117129
using namespace AsyncWebRequestMethod;
@@ -1556,7 +1568,7 @@ class AsyncWebServer : public AsyncMiddlewareChain {
15561568
bool removeHandler(AsyncWebHandler *handler);
15571569

15581570
AsyncCallbackWebHandler &on(AsyncURIMatcher uri, ArRequestHandlerFunction onRequest) {
1559-
return on(std::move(uri), AsyncWebRequestMethod::HTTP_ANY, onRequest);
1571+
return on(std::move(uri), AsyncWebRequestMethod::HTTP_ALL, onRequest);
15601572
}
15611573
AsyncCallbackWebHandler &on(
15621574
AsyncURIMatcher uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload = nullptr,

src/WebHandlerImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AsyncCallbackWebHandler : public AsyncWebHandler {
6262
bool _isRegex;
6363

6464
public:
65-
AsyncCallbackWebHandler() : _uri(), _method(AsyncWebRequestMethod::HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
65+
AsyncCallbackWebHandler() : _uri(), _method(AsyncWebRequestMethod::HTTP_ALL), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
6666
void setUri(AsyncURIMatcher uri);
6767
void setMethod(WebRequestMethodComposite method) {
6868
_method = method;

src/WebRequest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum {
4040

4141
AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer *s, AsyncClient *c)
4242
: _client(c), _server(s), _handler(NULL), _response(NULL), _onDisconnectfn(NULL), _temp(), _parseState(PARSE_REQ_START), _version(0),
43-
_method(AsyncWebRequestMethod::HTTP_ANY), _url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP),
43+
_method(AsyncWebRequestMethod::HTTP_ALL), _url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP),
4444
_authMethod(AsyncAuthType::AUTH_NONE), _isMultipart(false), _isPlainPost(false), _expectingContinue(false), _contentLength(0), _parsedLength(0),
4545
_multiParseState(0), _boundaryPosition(0), _itemStartIndex(0), _itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0),
4646
_itemBufferIndex(0), _itemIsFile(false), _chunkStartIndex(0), _chunkOffset(0), _chunkSize(0), _chunkedParseState(CHUNK_NONE), _chunkedLastChar(0),
@@ -1312,7 +1312,7 @@ String AsyncWebServerRequest::urlDecode(const String &text) const {
13121312
}
13131313

13141314
const char *AsyncWebServerRequest::methodToString() const {
1315-
if (_method == AsyncWebRequestMethod::HTTP_ANY) {
1315+
if (_method == AsyncWebRequestMethod::HTTP_ALL) {
13161316
return T_ANY;
13171317
}
13181318
if (_method & AsyncWebRequestMethod::HTTP_GET) {

0 commit comments

Comments
 (0)