4545#error Platform not supported
4646#endif
4747
48- // HTTP method enum from the underlying http_parser library.
49- // All supported TCP libraries (AsyncTCP, ESPAsyncTCP, RPAsyncTCP) are built on
50- // http_parser, so http_method is available on all supported platforms.
51- // Using the platform's enum avoids redefining HTTP_GET, HTTP_POST, etc. ourselves,
52- // which eliminates name conflicts with other libraries (e.g., Arduino WebServer.h).
53- #if __has_include(<http_parser.h>)
48+ // HTTP method types from the platform's HTTP parser library.
49+ // Arduino ESP32 core provides HTTP_Method.h which typedef's http_method as
50+ // HTTPMethod and defines HTTP_ANY = (HTTPMethod)(255) as the "match any" sentinel.
51+ // Fall back to the raw http_parser.h (always available via the TCP library) or,
52+ // as a last resort, to a fully inline fallback definition.
53+ #if __has_include(<HTTP_Method.h>)
54+ # include < HTTP_Method.h>
55+ // HTTP_Method.h provides: typedef enum http_method HTTPMethod;
56+ // and: #define HTTP_ANY (HTTPMethod)(255)
57+ #elif __has_include(<http_parser.h>)
5458# include < http_parser.h>
59+ // http_parser.h provides enum http_method but not the HTTP_ANY sentinel.
60+ // Define the sentinel here, matching the value used by Arduino's HTTP_Method.h.
61+ # ifndef HTTP_ANY
62+ # define HTTP_ANY ((http_method)(255 ))
63+ # endif
5564#else
56- // Fallback definition matching the llhttp/http_parser spec (used by all platforms) .
57- // This is provided only for toolchains that do not expose http_parser.h directly .
65+ // Full fallback for toolchains that expose neither header .
66+ // Enum values match the llhttp/http_parser spec used by all supported platforms .
5867typedef enum {
5968 HTTP_DELETE = 0 , HTTP_GET = 1 , HTTP_HEAD = 2 , HTTP_POST = 3 , HTTP_PUT = 4 ,
6069 HTTP_CONNECT = 5 , HTTP_OPTIONS = 6 , HTTP_TRACE = 7 , HTTP_COPY = 8 , HTTP_LOCK = 9 ,
@@ -65,6 +74,7 @@ typedef enum {
6574 HTTP_SUBSCRIBE = 26 , HTTP_UNSUBSCRIBE = 27 , HTTP_PATCH = 28 , HTTP_PURGE = 29 ,
6675 HTTP_MKCALENDAR = 30 , HTTP_LINK = 31 , HTTP_UNLINK = 32 ,
6776} http_method;
77+ # define HTTP_ANY ((http_method)(255 ))
6878#endif
6979
7080#include " AsyncWebServerVersion.h"
@@ -104,28 +114,35 @@ class AsyncMiddlewareChain;
104114// platform's http_parser enum. HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT,
105115// HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS, HTTP_PROPFIND, HTTP_LOCK, HTTP_UNLOCK,
106116// HTTP_PROPPATCH, HTTP_MKCOL, HTTP_MOVE, HTTP_COPY and many others are already
107- // defined globally by <http_parser.h> above — no redefinition needed here.
117+ // defined globally by the platform headers above — no redefinition needed here.
118+ // HTTP_ANY (= 255) is the "match any method" sentinel, also from the platform.
108119typedef http_method WebRequestMethod;
109120
110121// WebRequestMethodComposite: an ordered list of HTTP methods that a handler
111- // accepts. An empty composite matches *any* method ( HTTP_ANY / HTTP_ALL
112- // semantics) . Using a list avoids bitmask arithmetic on the platform enum's
122+ // accepts. An empty composite (or one that contains HTTP_ANY) matches *any*
123+ // method . Using a list avoids bitmask arithmetic on the platform enum's
113124// non-power-of-two sequential values.
114125class WebRequestMethodComposite {
115126public:
116127 // Maximum number of methods that can be listed. In practice, handlers
117- // accept at most a handful of methods; use the empty composite (HTTP_ALL)
118- // when you want to match any method.
128+ // accept at most a handful of methods; use HTTP_ANY when you want to
129+ // match any method.
119130 static const uint8_t MAX_METHODS = 8 ;
120131
121132 // Empty composite = match any method.
122133 WebRequestMethodComposite () : _count(0 ) {}
123134
124135 // Single-method composite. Intentionally implicit so that a bare
125136 // WebRequestMethod (e.g. HTTP_GET) is accepted wherever a composite is
126- // expected.
127- WebRequestMethodComposite (WebRequestMethod m) : _count(1 ) {
128- _methods[0 ] = m;
137+ // expected. HTTP_ANY (value 255) is treated as the "match any" sentinel:
138+ // it creates an empty composite rather than a single-method one.
139+ WebRequestMethodComposite (WebRequestMethod m) {
140+ if (m == static_cast <WebRequestMethod>(HTTP_ANY )) {
141+ _count = 0 ; // HTTP_ANY: match any method
142+ } else {
143+ _count = 1 ;
144+ _methods[0 ] = m;
145+ }
129146 }
130147
131148 // Append a method; silently ignores the call once MAX_METHODS is reached.
@@ -179,17 +196,6 @@ inline bool operator^(const WebRequestMethodComposite &c, WebRequestMethod m) {
179196 return c.contains (m);
180197}
181198
182- // HTTP_ALL: empty composite — matches any HTTP method.
183- // HTTP_ANY: backward-compatible alias for HTTP_ALL.
184- // HTTP_ANY is only defined here when external headers have not already defined
185- // it as a macro (e.g., Arduino core may define HTTP_ANY as an integer). When
186- // an external macro is present the name remains an integer; user code should
187- // migrate to HTTP_ALL which is always safe.
188- #define HTTP_ALL WebRequestMethodComposite ()
189- #ifndef HTTP_ANY
190- #define HTTP_ANY WebRequestMethodComposite ()
191- #endif
192-
193199#ifndef HAVE_FS_FILE_OPEN_MODE
194200namespace fs {
195201class FileOpenMode {
@@ -1629,7 +1635,7 @@ class AsyncWebServer : public AsyncMiddlewareChain {
16291635 bool removeHandler (AsyncWebHandler *handler);
16301636
16311637 AsyncCallbackWebHandler &on (AsyncURIMatcher uri, ArRequestHandlerFunction onRequest) {
1632- return on (std::move (uri), HTTP_ALL , onRequest);
1638+ return on (std::move (uri), HTTP_ANY , onRequest);
16331639 }
16341640 AsyncCallbackWebHandler &on (
16351641 AsyncURIMatcher uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload = nullptr ,
0 commit comments