From e28aa5e3fc0e19c7844ea9e322e1ae5a2beced22 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Wed, 11 Sep 2024 21:56:23 +0200 Subject: [PATCH] #define RESPONSE_STREAM_BUFFER_SIZE 1460 --- src/ESPAsyncWebServer.h | 5 +++-- src/WebRequest.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ESPAsyncWebServer.h b/src/ESPAsyncWebServer.h index 0fce863..3b4e175 100644 --- a/src/ESPAsyncWebServer.h +++ b/src/ESPAsyncWebServer.h @@ -101,6 +101,7 @@ namespace fs { // if this value is returned when asked for data, packet will not be sent and you will be asked for data again #define RESPONSE_TRY_AGAIN 0xFFFFFFFF +#define RESPONSE_STREAM_BUFFER_SIZE 1460 typedef uint8_t WebRequestMethodComposite; typedef std::function ArDisconnectHandler; @@ -377,8 +378,8 @@ class AsyncWebServerRequest { AsyncWebServerResponse* beginChunkedResponse(const char* contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr); AsyncWebServerResponse* beginChunkedResponse(const String& contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr); - AsyncResponseStream* beginResponseStream(const char* contentType, size_t bufferSize = 1460); - AsyncResponseStream* beginResponseStream(const String& contentType, size_t bufferSize = 1460) { return beginResponseStream(contentType.c_str(), bufferSize); } + AsyncResponseStream* beginResponseStream(const char* contentType, size_t bufferSize = RESPONSE_STREAM_BUFFER_SIZE); + AsyncResponseStream* beginResponseStream(const String& contentType, size_t bufferSize = RESPONSE_STREAM_BUFFER_SIZE) { return beginResponseStream(contentType.c_str(), bufferSize); } #ifndef ESP8266 [[deprecated("Replaced by beginResponse(...)")]] diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index da17d7a..0dd0d21 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -340,7 +340,7 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data) { void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last) { _itemBuffer[_itemBufferIndex++] = data; - if (last || _itemBufferIndex == 1460) { + if (last || _itemBufferIndex == RESPONSE_STREAM_BUFFER_SIZE) { // check if authenticated before calling the upload if (_handler) _handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false); @@ -444,7 +444,7 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) { if (_itemIsFile) { if (_itemBuffer) free(_itemBuffer); - _itemBuffer = (uint8_t*)malloc(1460); + _itemBuffer = (uint8_t*)malloc(RESPONSE_STREAM_BUFFER_SIZE); if (_itemBuffer == NULL) { _multiParseState = PARSE_ERROR; return;