Put HTTP_METHOD symbols in namespace#400
Open
willmmiles wants to merge 3 commits intoESP32Async:mainfrom
Open
Conversation
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.
mathieucarbou
approved these changes
Mar 9, 2026
5 tasks
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) { |
Member
There was a problem hiding this comment.
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;
Author
There was a problem hiding this comment.
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. :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inSeems to be some kind of codespace weirdness.arduino-3?)