Skip to content

Fix HTTP method conflicts with Arduino core: use HTTP_Method.h enum and list-based composite#403

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-http-any-conflict
Closed

Fix HTTP method conflicts with Arduino core: use HTTP_Method.h enum and list-based composite#403
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-http-any-conflict

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 13, 2026

Arduino core headers (e.g., WebServer.h, HTTPClient.h) define HTTP method names such as HTTP_ANY as preprocessor macros or global enum values. Because macros expand before C++ name resolution, any namespace-qualified reference like AsyncWebRequestMethod::HTTP_ANY would silently expand to AsyncWebRequestMethod::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 #undef guards and opt-out macros, the library now delegates HTTP method identity entirely to the platform:

  • Remove the AsyncWebRequestMethod namespace and AsyncWebRequestMethodType bitmask enum entirely.
  • Remove ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODS and ASYNCWEBSERVER_NO_HTTP_ANY opt-out macros.
  • Include <HTTP_Method.h> (Arduino ESP32 core) first, which provides typedef enum http_method HTTPMethod and #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_ANY definition. 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_method uses sequential integers (not powers of two), bitwise OR cannot encode method sets. WebRequestMethodComposite is now a fixed-size ordered list of WebRequestMethod values:

// Build a composite:
server.on("/api", HTTP_GET | HTTP_POST, handler);      // 2-method composite
server.on("/api", HTTP_GET | HTTP_POST | HTTP_PUT, handler);

// Membership test (operator^):
if (handlerMethods ^ request->method()) { /* matched */ }

// Match any method — use the platform's HTTP_ANY sentinel (value 255):
server.on("/", HTTP_ANY, handler);
server.on("/", handler);             // same via overload

operator| builds the list. operator^ tests membership. WebRequestMethodComposite(HTTP_ANY) creates an empty (match-any) composite — equivalent to the default constructor.

HTTP_ANY

HTTP_ANY is the platform-provided "match any method" sentinel ((HTTPMethod)(255) from Arduino's HTTP_Method.h). No library-defined HTTP_ALL is needed or provided. HTTP_ANY is defined consistently across all supported platforms via the 3-way include fallback above.

Additional fixes

  • AsyncWebServerRequest::_method changed from WebRequestMethodComposite to WebRequestMethod; method() return type updated accordingly.
  • Fix long-standing constexpr static bool JsonHandlerMethods bug in AsyncJson.cpp (previously stored the result of bitwise OR of enum values into a bool).
  • All canHandle checks updated from bitmask & to operator^.
  • Documentation (docs/setup.md, docs/backup/wiki.md) updated to use HTTP_ANY.

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Fix conflict with Arduino core HTTP_ANY macro Fix HTTP_ANY macro conflict with Arduino core Mar 13, 2026
Copilot AI requested a review from mathieucarbou March 13, 2026 21:20
@mathieucarbou
Copy link
Copy Markdown
Member

@copilot also update the website in the docs folder.

@mathieucarbou
Copy link
Copy Markdown
Member

This an attempt at making Copilot fix the conflict issue raised in #402 when including Arduino WebServer headers at the same time as ESpAsyncWebServer.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ANY to HTTP_ALL.
  • Update internal defaults/usages to use HTTP_ALL.
  • Add a backward-compatibility HTTP_ANY alias 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.

Comment thread src/ESPAsyncWebServer.h Outdated
Copy link
Copy Markdown
Author

Copilot AI commented Mar 13, 2026

@copilot also update the website in the docs folder.

Done in d36b720 — replaced all HTTP_ANY occurrences with HTTP_ALL in docs/setup.md and docs/backup/wiki.md.

@mathieucarbou mathieucarbou marked this pull request as ready for review March 13, 2026 22:12
@mathieucarbou mathieucarbou self-requested a review March 13, 2026 22:19
@mathieucarbou
Copy link
Copy Markdown
Member

@copilot :

  1. rebase this PR in top of fix-400 branch

  2. remove all the namespace stuff, ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODS and ASYNCWEBSERVER_NO_HTTP_ANY macros and solve the issue by using another approach:

  • completely remove our AsyncWebRequestMethodType enum
  • use instead the one from arduino (HTTP_ANY) and esp-idf to by including HTTP_Method.h and avoir any conflict with other project
  • typedef http_method WebRequestMethod;
  • change the WebRequestMethodComposite type into a list that contains WebRequestMethod
  • overload operator | for WebRequestMethod and WebRequestMethodComposite so that usages of HTTP_GET | HTTP_POST builds a list behind
  • overload operator ^ so that it checks the content of the list instead of checking the bit mask
  • I nsummary the idea is to keep out existing types, remove our enum, use instead the arduino core / esp-idf one and use a list instead of a bit mask because their enum does not support bit masking.

Copy link
Copy Markdown
Author

Copilot AI commented Mar 14, 2026

@copilot :

  1. rebase this PR in top of fix-400 branch
    ...

Done in e0a7b64. Here's what was changed:

  1. Rebased onto fix-400 — the constexpr static bool JsonHandlerMethods bug from that branch is now fixed inline in AsyncJson.cpp.

  2. Namespace removedAsyncWebRequestMethod namespace, ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODS, and ASYNCWEBSERVER_NO_HTTP_ANY are all gone.

  3. Platform enum#include <http_parser.h> (with a __has_include fallback enum for platforms that don't expose it directly). typedef http_method WebRequestMethod;HTTP_GET, HTTP_POST, etc. now come from the platform, not from our own definition.

  4. List-based compositeWebRequestMethodComposite is now a fixed-size (8-slot) list of WebRequestMethod values. An empty composite matches any method.

    • operator| builds the list: HTTP_GET | HTTP_POST → a 2-entry composite
    • operator^ checks membership: handlerMethods ^ request->method()bool
  5. HTTP_ALL#define HTTP_ALL WebRequestMethodComposite() (always safe, not a macro the platform defines).
    HTTP_ANY — same definition but #ifndef-guarded: if Arduino's headers already defined HTTP_ANY as an integer macro, we leave it untouched; user code that passes the integer HTTP_ANY to a method-accepting function will get a clear compile error (no implicit int→enum conversion in C++) prompting migration to HTTP_ALL.

  6. AsyncWebServerRequest::_method changed from WebRequestMethodComposite to WebRequestMethod; method() now returns WebRequestMethod.

Copilot AI changed the title Fix HTTP_ANY macro conflict with Arduino core Fix HTTP method conflicts with Arduino core: use http_parser enum and list-based composite Mar 14, 2026
@mathieucarbou
Copy link
Copy Markdown
Member

@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.

Copy link
Copy Markdown
Author

Copilot AI commented Mar 14, 2026

@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. HTTP_ALL is removed. The include order is now:

  1. #include <HTTP_Method.h> — Arduino ESP32 core, provides typedef enum http_method HTTPMethod and #define HTTP_ANY (HTTPMethod)(255)
  2. #elif __has_include(<http_parser.h>) — all other platforms, plus #define HTTP_ANY ((http_method)(255)) to match Arduino's value
  3. Inline fallback enum + #define HTTP_ANY ((http_method)(255))

WebRequestMethodComposite(WebRequestMethod m) now special-cases HTTP_ANY (value 255): it creates an empty composite (match any) instead of a single-method one, so server.on("/", HTTP_ANY, handler) and server.on("/", handler) are equivalent. Docs updated to use HTTP_ANY throughout.

Copilot AI changed the title Fix HTTP method conflicts with Arduino core: use http_parser enum and list-based composite Fix HTTP method conflicts with Arduino core: use HTTP_Method.h enum and list-based composite Mar 14, 2026
@mathieucarbou mathieucarbou force-pushed the copilot/fix-http-any-conflict branch from 7eefa6b to f01d021 Compare March 14, 2026 12:19
@mathieucarbou mathieucarbou force-pushed the copilot/fix-http-any-conflict branch from f01d021 to 12a670f Compare March 14, 2026 12:42
@mathieucarbou mathieucarbou deleted the copilot/fix-http-any-conflict branch March 14, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants