Skip to content

Commit a77aeaf

Browse files
committed
Fix ASYNCWEBSERVER_NO_GLOBAL_HTTP_METHODS
Ensure we're always using our AsyncWebRequestMethod internally.
1 parent d56803f commit a77aeaf

6 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/AsyncJson.cpp

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

44
#include "AsyncJson.h"
55
#include "AsyncWebServerLogging.h"
6+
using namespace AsyncWebRequestMethod;
67

78
#include <utility>
89

src/ESPAsyncWebServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ class AsyncWebServerRequest {
385385
bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, RequestedConnectionType erct3 = RCT_NOT_USED)
386386
const;
387387
bool isWebSocketUpgrade() const {
388-
return _method == HTTP_GET && isExpectedRequestedConnType(RCT_WS);
388+
return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_WS);
389389
}
390390
bool isSSE() const {
391-
return _method == HTTP_GET && isExpectedRequestedConnType(RCT_EVENT);
391+
return _method == AsyncWebRequestMethod::HTTP_GET && isExpectedRequestedConnType(RCT_EVENT);
392392
}
393393
bool isHTTP() const {
394394
return isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP);
@@ -1558,7 +1558,7 @@ class AsyncWebServer : public AsyncMiddlewareChain {
15581558
bool removeHandler(AsyncWebHandler *handler);
15591559

15601560
AsyncCallbackWebHandler &on(AsyncURIMatcher uri, ArRequestHandlerFunction onRequest) {
1561-
return on(std::move(uri), HTTP_ANY, onRequest);
1561+
return on(std::move(uri), AsyncWebRequestMethod::HTTP_ANY, onRequest);
15621562
}
15631563
AsyncCallbackWebHandler &on(
15641564
AsyncURIMatcher uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload = nullptr,

src/Middleware.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void AsyncCorsMiddleware::run(AsyncWebServerRequest *request, ArMiddlewareNext n
249249
// Origin header ? => CORS handling
250250
if (request->hasHeader(asyncsrv::T_CORS_O)) {
251251
// check if this is a preflight request => handle it and return
252-
if (request->method() == HTTP_OPTIONS) {
252+
if (request->method() == AsyncWebRequestMethod::HTTP_OPTIONS) {
253253
AsyncWebServerResponse *response = request->beginResponse(200);
254254
addCORSHeaders(request, response);
255255
request->send(response);

src/WebHandlerImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AsyncCallbackWebHandler : public AsyncWebHandler {
6262
bool _isRegex;
6363

6464
public:
65-
AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
65+
AsyncCallbackWebHandler() : _uri(), _method(AsyncWebRequestMethod::HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), _isRegex(false) {}
6666
void setUri(AsyncURIMatcher uri);
6767
void setMethod(WebRequestMethodComposite method) {
6868
_method = method;

src/WebHandlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ AsyncStaticWebHandler &AsyncStaticWebHandler::setLastModified() {
103103
}
104104

105105
bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request) const {
106-
return request->isHTTP() && request->method() == HTTP_GET && request->url().startsWith(_uri) && _getFile(request);
106+
return request->isHTTP() && request->method() == AsyncWebRequestMethod::HTTP_GET && request->url().startsWith(_uri) && _getFile(request);
107107
}
108108

109109
bool AsyncStaticWebHandler::_getFile(AsyncWebServerRequest *request) const {

src/WebRequest.cpp

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

1414
#include "./literals.h"
1515

16+
// Bring in HTTP namespace
17+
using namespace AsyncWebRequestMethod;
18+
1619
static inline bool isParamChar(char c) {
1720
return ((c) && ((c) != '{') && ((c) != '[') && ((c) != '&') && ((c) != '='));
1821
}

0 commit comments

Comments
 (0)