fix #339 maxJsonBuffrSize

This commit is contained in:
MichaelDvP
2022-03-21 13:44:40 +01:00
parent 3b5560b741
commit 786110359a
2 changed files with 8 additions and 4 deletions

View File

@@ -173,7 +173,7 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
ArJsonRequestHandlerFunction _onRequest;
size_t _contentLength;
#ifndef ARDUINOJSON_5_COMPATIBILITY
const size_t maxJsonBufferSize;
size_t _maxJsonBufferSize;
#endif
size_t _maxContentLength;
@@ -182,7 +182,7 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
: _uri(uri)
, _method(HTTP_POST | HTTP_PUT | HTTP_PATCH)
, _onRequest(onRequest)
, maxJsonBufferSize(maxJsonBufferSize)
, _maxJsonBufferSize(maxJsonBufferSize)
, _maxContentLength(16384) {
}
@@ -192,6 +192,9 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
void setMaxContentLength(int maxContentLength) {
_maxContentLength = maxContentLength;
}
void setMaxJsonBufferSize(size_t maxJsonBufferSize) {
_maxJsonBufferSize = maxJsonBufferSize;
}
void onRequest(ArJsonRequestHandlerFunction fn) {
_onRequest = fn;
}
@@ -216,7 +219,7 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
virtual void handleRequest(AsyncWebServerRequest * request) override final {
if (_onRequest) {
if (request->_tempObject != NULL) {
DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize);
DynamicJsonDocument jsonBuffer(this->_maxJsonBufferSize);
DeserializationError error = deserializeJson(jsonBuffer, (uint8_t *)(request->_tempObject));
if (!error) {
JsonVariant json = jsonBuffer.as<JsonVariant>();

View File

@@ -46,7 +46,8 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
securityManager->wrapRequest(std::bind(&WebCustomizationService::reset_customization, this, _1), AuthenticationPredicates::IS_ADMIN));
_exclude_entities_handler.setMethod(HTTP_POST);
_exclude_entities_handler.setMaxContentLength(1024);
_exclude_entities_handler.setMaxContentLength(2048);
_exclude_entities_handler.setMaxJsonBufferSize(2048);
server->addHandler(&_exclude_entities_handler);
_device_entities_handler.setMethod(HTTP_POST);