Skip to content

Put HTTP_METHOD symbols in namespace#400

Open
willmmiles wants to merge 3 commits intoESP32Async:mainfrom
willmmiles:namespace-method-names
Open

Put HTTP_METHOD symbols in namespace#400
willmmiles wants to merge 3 commits intoESP32Async:mainfrom
willmmiles:namespace-method-names

Conversation

@willmmiles
Copy link

@willmmiles willmmiles commented Mar 9, 2026

Always formally define the WebRequestMethod type, and put the HTTP_METHOD symbols in a namespace that does not have to be included. This allows us to avoid collisions with other web server libraries that may define the same symbols globally.

Also we remove the includes of such colliding symbols on RP-Pico targets.

Fixes #398

(and curiously seems to result a slightly smaller binary in arduino-3?) Seems to be some kind of codespace weirdness.

Always formally define the WebRequestMethod type, and put the
HTTP_METHOD symbols in a namespace that does not have to be included.
This allows us to avoid collisions with other web server libraries that
may define the same symbols globally.

Also we remove the includes of such colliding symbols on RP-Pico
targets.
Ensure we're always using our AsyncWebRequestMethod internally.
if (request->hasHeader(asyncsrv::T_CORS_O)) {
// check if this is a preflight request => handle it and return
if (request->method() == HTTP_OPTIONS) {
if (request->method() == AsyncWebRequestMethod::HTTP_OPTIONS) {
Copy link
Member

Choose a reason for hiding this comment

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

Why src/WebRequest.cpp and src/AsyncJson.cpp are updated to use the namespace while this cpp prefixes the constant with the namespace ? Wouldn't it be easier to just do that in all cpp files requiring these enums for consistency ?

// Bring in HTTP namespace
using namespace AsyncWebRequestMethod;

Copy link
Author

Choose a reason for hiding this comment

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

An excellent question! Best practices for C++ are to use fully qualified symbols where possible to avoid any possible risk of collisions should platform libraries change out from under you -- or at worst, apply using directives to individual functions. I got lazy. Thanks for calling me out. :)

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.

HTTP Method matching is incorrect on RP2040 / RP2350

2 participants