Skip to content

Commit e0c85cb

Browse files
committed
Remove using AsyncWebRequestMethod
Prefer fully qualitifed references instead.
1 parent e5d7b20 commit e0c85cb

3 files changed

Lines changed: 44 additions & 46 deletions

File tree

src/AsyncJson.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "AsyncJson.h"
55
#include "AsyncWebServerLogging.h"
6-
using namespace AsyncWebRequestMethod;
76

87
#include <utility>
98

@@ -113,14 +112,15 @@ size_t AsyncMessagePackResponse::_fillBuffer(uint8_t *data, size_t len) {
113112
#endif
114113

115114
// Body handler supporting both content types: JSON and MessagePack
115+
constexpr static bool JsonHandlerMethods =
116+
AsyncWebRequestMethod::HTTP_GET | AsyncWebRequestMethod::HTTP_POST | AsyncWebRequestMethod::HTTP_PUT | AsyncWebRequestMethod::HTTP_PATCH;
116117

117118
#if ARDUINOJSON_VERSION_MAJOR == 6
118119
AsyncCallbackJsonWebHandler::AsyncCallbackJsonWebHandler(AsyncURIMatcher uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize)
119-
: _uri(std::move(uri)), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize),
120-
_maxContentLength(16384) {}
120+
: _uri(std::move(uri)), _method(JsonHandlerTypes), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
121121
#else
122122
AsyncCallbackJsonWebHandler::AsyncCallbackJsonWebHandler(AsyncURIMatcher uri, ArJsonRequestHandlerFunction onRequest)
123-
: _uri(std::move(uri)), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
123+
: _uri(std::move(uri)), _method(JsonHandlerMethods), _onRequest(onRequest), _maxContentLength(16384) {}
124124
#endif
125125

126126
bool AsyncCallbackJsonWebHandler::canHandle(AsyncWebServerRequest *request) const {
@@ -133,17 +133,17 @@ bool AsyncCallbackJsonWebHandler::canHandle(AsyncWebServerRequest *request) cons
133133
}
134134

135135
#if ASYNC_MSG_PACK_SUPPORT == 1
136-
return request->method() == HTTP_GET || request->contentType().equalsIgnoreCase(asyncsrv::T_application_json)
136+
return request->method() == AsyncWebRequestMethod::HTTP_GET || request->contentType().equalsIgnoreCase(asyncsrv::T_application_json)
137137
|| request->contentType().equalsIgnoreCase(asyncsrv::T_application_msgpack);
138138
#else
139-
return request->method() == HTTP_GET || request->contentType().equalsIgnoreCase(asyncsrv::T_application_json);
139+
return request->method() == AsyncWebRequestMethod::HTTP_GET || request->contentType().equalsIgnoreCase(asyncsrv::T_application_json);
140140
#endif
141141
}
142142

143143
void AsyncCallbackJsonWebHandler::handleRequest(AsyncWebServerRequest *request) {
144144
if (_onRequest) {
145145
// GET request:
146-
if (request->method() == HTTP_GET) {
146+
if (request->method() == AsyncWebRequestMethod::HTTP_GET) {
147147
JsonVariant json;
148148
_onRequest(request, json);
149149
return;

src/ESPAsyncWebServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ typedef AsyncWebRequestMethod::AsyncWebRequestMethodType WebRequestMethod;
105105
typedef uint16_t WebRequestMethodComposite;
106106

107107
// Type-safe helper functions for composite methods
108-
extern inline WebRequestMethodComposite operator|(WebRequestMethodComposite l, WebRequestMethod r) {
108+
extern constexpr inline WebRequestMethodComposite operator|(WebRequestMethodComposite l, WebRequestMethod r) {
109109
return l | static_cast<WebRequestMethodComposite>(r);
110110
};
111-
extern inline WebRequestMethodComposite operator|(WebRequestMethod l, WebRequestMethod r) {
111+
extern constexpr inline WebRequestMethodComposite operator|(WebRequestMethod l, WebRequestMethod r) {
112112
return static_cast<WebRequestMethodComposite>(l) | r;
113113
};
114114

src/WebRequest.cpp

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
#include "./literals.h"
1515

16-
// Bring in HTTP namespace
17-
using namespace AsyncWebRequestMethod;
18-
1916
static inline bool isParamChar(char c) {
2017
return ((c) && ((c) != '{') && ((c) != '[') && ((c) != '&') && ((c) != '='));
2118
}
@@ -42,11 +39,12 @@ enum {
4239
};
4340

4441
AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer *s, AsyncClient *c)
45-
: _client(c), _server(s), _handler(NULL), _response(NULL), _onDisconnectfn(NULL), _temp(), _parseState(PARSE_REQ_START), _version(0), _method(HTTP_ANY),
46-
_url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP), _authMethod(AsyncAuthType::AUTH_NONE), _isMultipart(false),
47-
_isPlainPost(false), _expectingContinue(false), _contentLength(0), _parsedLength(0), _multiParseState(0), _boundaryPosition(0), _itemStartIndex(0),
48-
_itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0), _itemBufferIndex(0), _itemIsFile(false), _chunkStartIndex(0),
49-
_chunkOffset(0), _chunkSize(0), _chunkedParseState(CHUNK_NONE), _chunkedLastChar(0), _tempObject(NULL) {
42+
: _client(c), _server(s), _handler(NULL), _response(NULL), _onDisconnectfn(NULL), _temp(), _parseState(PARSE_REQ_START), _version(0),
43+
_method(AsyncWebRequestMethod::HTTP_ANY), _url(), _host(), _contentType(), _boundary(), _authorization(), _reqconntype(RCT_HTTP),
44+
_authMethod(AsyncAuthType::AUTH_NONE), _isMultipart(false), _isPlainPost(false), _expectingContinue(false), _contentLength(0), _parsedLength(0),
45+
_multiParseState(0), _boundaryPosition(0), _itemStartIndex(0), _itemSize(0), _itemName(), _itemFilename(), _itemType(), _itemValue(), _itemBuffer(0),
46+
_itemBufferIndex(0), _itemIsFile(false), _chunkStartIndex(0), _chunkOffset(0), _chunkSize(0), _chunkedParseState(CHUNK_NONE), _chunkedLastChar(0),
47+
_tempObject(NULL) {
5048
c->onError(
5149
[](void *r, AsyncClient *c, int8_t error) {
5250
(void)c;
@@ -317,33 +315,33 @@ bool AsyncWebServerRequest::_parseReqHead() {
317315
_temp = _temp.substring(index + 1);
318316

319317
if (m == T_GET) {
320-
_method = HTTP_GET;
318+
_method = AsyncWebRequestMethod::HTTP_GET;
321319
} else if (m == T_POST) {
322-
_method = HTTP_POST;
320+
_method = AsyncWebRequestMethod::HTTP_POST;
323321
} else if (m == T_DELETE) {
324-
_method = HTTP_DELETE;
322+
_method = AsyncWebRequestMethod::HTTP_DELETE;
325323
} else if (m == T_PUT) {
326-
_method = HTTP_PUT;
324+
_method = AsyncWebRequestMethod::HTTP_PUT;
327325
} else if (m == T_PATCH) {
328-
_method = HTTP_PATCH;
326+
_method = AsyncWebRequestMethod::HTTP_PATCH;
329327
} else if (m == T_HEAD) {
330-
_method = HTTP_HEAD;
328+
_method = AsyncWebRequestMethod::HTTP_HEAD;
331329
} else if (m == T_OPTIONS) {
332-
_method = HTTP_OPTIONS;
330+
_method = AsyncWebRequestMethod::HTTP_OPTIONS;
333331
} else if (m == T_PROPFIND) {
334-
_method = HTTP_PROPFIND;
332+
_method = AsyncWebRequestMethod::HTTP_PROPFIND;
335333
} else if (m == T_LOCK) {
336-
_method = HTTP_LOCK;
334+
_method = AsyncWebRequestMethod::HTTP_LOCK;
337335
} else if (m == T_UNLOCK) {
338-
_method = HTTP_UNLOCK;
336+
_method = AsyncWebRequestMethod::HTTP_UNLOCK;
339337
} else if (m == T_PROPPATCH) {
340-
_method = HTTP_PROPPATCH;
338+
_method = AsyncWebRequestMethod::HTTP_PROPPATCH;
341339
} else if (m == T_MKCOL) {
342-
_method = HTTP_MKCOL;
340+
_method = AsyncWebRequestMethod::HTTP_MKCOL;
343341
} else if (m == T_MOVE) {
344-
_method = HTTP_MOVE;
342+
_method = AsyncWebRequestMethod::HTTP_MOVE;
345343
} else if (m == T_COPY) {
346-
_method = HTTP_COPY;
344+
_method = AsyncWebRequestMethod::HTTP_COPY;
347345
} else {
348346
return false;
349347
}
@@ -1314,49 +1312,49 @@ String AsyncWebServerRequest::urlDecode(const String &text) const {
13141312
}
13151313

13161314
const char *AsyncWebServerRequest::methodToString() const {
1317-
if (_method == HTTP_ANY) {
1315+
if (_method == AsyncWebRequestMethod::HTTP_ANY) {
13181316
return T_ANY;
13191317
}
1320-
if (_method & HTTP_GET) {
1318+
if (_method & AsyncWebRequestMethod::HTTP_GET) {
13211319
return T_GET;
13221320
}
1323-
if (_method & HTTP_POST) {
1321+
if (_method & AsyncWebRequestMethod::HTTP_POST) {
13241322
return T_POST;
13251323
}
1326-
if (_method & HTTP_DELETE) {
1324+
if (_method & AsyncWebRequestMethod::HTTP_DELETE) {
13271325
return T_DELETE;
13281326
}
1329-
if (_method & HTTP_PUT) {
1327+
if (_method & AsyncWebRequestMethod::HTTP_PUT) {
13301328
return T_PUT;
13311329
}
1332-
if (_method & HTTP_PATCH) {
1330+
if (_method & AsyncWebRequestMethod::HTTP_PATCH) {
13331331
return T_PATCH;
13341332
}
1335-
if (_method & HTTP_HEAD) {
1333+
if (_method & AsyncWebRequestMethod::HTTP_HEAD) {
13361334
return T_HEAD;
13371335
}
1338-
if (_method & HTTP_OPTIONS) {
1336+
if (_method & AsyncWebRequestMethod::HTTP_OPTIONS) {
13391337
return T_OPTIONS;
13401338
}
1341-
if (_method & HTTP_PROPFIND) {
1339+
if (_method & AsyncWebRequestMethod::HTTP_PROPFIND) {
13421340
return T_PROPFIND;
13431341
}
1344-
if (_method & HTTP_LOCK) {
1342+
if (_method & AsyncWebRequestMethod::HTTP_LOCK) {
13451343
return T_LOCK;
13461344
}
1347-
if (_method & HTTP_UNLOCK) {
1345+
if (_method & AsyncWebRequestMethod::HTTP_UNLOCK) {
13481346
return T_UNLOCK;
13491347
}
1350-
if (_method & HTTP_PROPPATCH) {
1348+
if (_method & AsyncWebRequestMethod::HTTP_PROPPATCH) {
13511349
return T_PROPPATCH;
13521350
}
1353-
if (_method & HTTP_MKCOL) {
1351+
if (_method & AsyncWebRequestMethod::HTTP_MKCOL) {
13541352
return T_MKCOL;
13551353
}
1356-
if (_method & HTTP_MOVE) {
1354+
if (_method & AsyncWebRequestMethod::HTTP_MOVE) {
13571355
return T_MOVE;
13581356
}
1359-
if (_method & HTTP_COPY) {
1357+
if (_method & AsyncWebRequestMethod::HTTP_COPY) {
13601358
return T_COPY;
13611359
}
13621360
return T_UNKNOWN;

0 commit comments

Comments
 (0)