mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-09-09 22:30:54 +02:00
Reapplied changes from https://github.com/me-no-dev/ESPAsyncWebServer/pull/1384
This commit is contained in:
committed by
Mathieu Carbou
parent
64706c15ed
commit
f477fa5f35
@@ -197,10 +197,10 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
|||||||
public:
|
public:
|
||||||
#if ARDUINOJSON_VERSION_MAJOR == 6
|
#if ARDUINOJSON_VERSION_MAJOR == 6
|
||||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
|
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
|
||||||
: _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
|
: _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), _maxContentLength(16384) {}
|
||||||
#else
|
#else
|
||||||
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest)
|
AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest)
|
||||||
: _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
: _uri(uri), _method(HTTP_GET | HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setMethod(WebRequestMethodComposite method) { _method = method; }
|
void setMethod(WebRequestMethodComposite method) { _method = method; }
|
||||||
@@ -211,13 +211,14 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
|||||||
if (!_onRequest)
|
if (!_onRequest)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(_method & request->method()))
|
WebRequestMethodComposite request_method = request->method();
|
||||||
|
if (!(_method & request_method))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
|
if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/")))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!request->contentType().equalsIgnoreCase(JSON_MIMETYPE))
|
if (request_method != HTTP_GET && !request->contentType().equalsIgnoreCase(JSON_MIMETYPE))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
request->addInterestingHeader("ANY");
|
request->addInterestingHeader("ANY");
|
||||||
@@ -225,8 +226,14 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void handleRequest(AsyncWebServerRequest* request) override final {
|
virtual void handleRequest(AsyncWebServerRequest* request) override final {
|
||||||
|
if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
|
||||||
|
return request->requestAuthentication();
|
||||||
if (_onRequest) {
|
if (_onRequest) {
|
||||||
if (request->_tempObject != NULL) {
|
if (request->method() == HTTP_GET) {
|
||||||
|
JsonVariant json;
|
||||||
|
_onRequest(request, json);
|
||||||
|
return;
|
||||||
|
} else if (request->_tempObject != NULL) {
|
||||||
|
|
||||||
#if ARDUINOJSON_VERSION_MAJOR == 5
|
#if ARDUINOJSON_VERSION_MAJOR == 5
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
|
Reference in New Issue
Block a user