Fix HTTP method conflicts with Arduino core: use HTTP_Method.h enum and list-based composite#403
Fix HTTP method conflicts with Arduino core: use HTTP_Method.h enum and list-based composite#403Copilot wants to merge 2 commits into
Conversation
|
@copilot also update the website in the docs folder. |
|
This an attempt at making Copilot fix the conflict issue raised in #402 when including Arduino WebServer headers at the same time as ESpAsyncWebServer. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a compile-time conflict between Arduino core HTTP client headers that define HTTP_ANY as a preprocessor macro and this library’s AsyncWebRequestMethod::HTTP_ANY symbol.
Changes:
- Rename the canonical “all methods” enum value from
HTTP_ANYtoHTTP_ALL. - Update internal defaults/usages to use
HTTP_ALL. - Add a backward-compatibility
HTTP_ANYalias in the header (with macro handling) to preserve the old symbol where possible.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/WebRequest.cpp | Switch default request method and method string mapping to HTTP_ALL. |
| src/WebHandlerImpl.h | Switch default callback handler method to HTTP_ALL. |
| src/ESPAsyncWebServer.h | Introduce HTTP_ALL, add HTTP_ANY alias, and update the default on() overload to use HTTP_ALL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot :
|
Done in e0a7b64. Here's what was changed:
|
|
@copilot : I think you could get rid of HTTP_ALL and keep the existing HTTP_ANY that is defined in HTTP_Methods.h : it is defined as 255. |
Done in 7eefa6b.
|
7eefa6b to
f01d021
Compare
…nd list-based composite
f01d021 to
12a670f
Compare
Arduino core headers (e.g.,
WebServer.h,HTTPClient.h) define HTTP method names such asHTTP_ANYas preprocessor macros or global enum values. Because macros expand before C++ name resolution, any namespace-qualified reference likeAsyncWebRequestMethod::HTTP_ANYwould silently expand toAsyncWebRequestMethod::0— a compile error. Bitmask-based enums also conflict when the platform enum uses sequential (non-power-of-two) values.Approach
Rather than patching around the conflict with
#undefguards and opt-out macros, the library now delegates HTTP method identity entirely to the platform:AsyncWebRequestMethodnamespace andAsyncWebRequestMethodTypebitmask enum entirely.ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODSandASYNCWEBSERVER_NO_HTTP_ANYopt-out macros.<HTTP_Method.h>(Arduino ESP32 core) first, which providestypedef enum http_method HTTPMethodand#define HTTP_ANY (HTTPMethod)(255). Falls back to<http_parser.h>(with#define HTTP_ANY ((http_method)(255))), then to a fully inline fallback enum +HTTP_ANYdefinition.HTTP_GET,HTTP_POST,HTTP_DELETE, etc. now come from the platform — the library defines none of them, eliminating the source of all naming conflicts.typedef http_method WebRequestMethod;— single HTTP method type, directly from the platform enum.New composite type
Because
http_methoduses sequential integers (not powers of two), bitwise OR cannot encode method sets.WebRequestMethodCompositeis now a fixed-size ordered list ofWebRequestMethodvalues:operator|builds the list.operator^tests membership.WebRequestMethodComposite(HTTP_ANY)creates an empty (match-any) composite — equivalent to the default constructor.HTTP_ANYHTTP_ANYis the platform-provided "match any method" sentinel ((HTTPMethod)(255)from Arduino'sHTTP_Method.h). No library-definedHTTP_ALLis needed or provided.HTTP_ANYis defined consistently across all supported platforms via the 3-way include fallback above.Additional fixes
AsyncWebServerRequest::_methodchanged fromWebRequestMethodCompositetoWebRequestMethod;method()return type updated accordingly.constexpr static bool JsonHandlerMethodsbug inAsyncJson.cpp(previously stored the result of bitwise OR of enum values into abool).canHandlechecks updated from bitmask&tooperator^.docs/setup.md,docs/backup/wiki.md) updated to useHTTP_ANY.📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.