From 8f28c88f9c71fd46f448760105bf49e390aa2cfc Mon Sep 17 00:00:00 2001 From: DiamondDrake Date: Thu, 29 Nov 2018 20:24:55 -0500 Subject: [PATCH] Added naive content length to upload struct (#5142) Content length provides context into the size of the upload, it's not the exact form body size it's off by the request header info, but it was already parsed by the library and provides little to no additional overhead to pass on for use in request handlers. --- libraries/ESP8266WebServer/src/ESP8266WebServer.h | 3 ++- libraries/ESP8266WebServer/src/Parsing.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.h b/libraries/ESP8266WebServer/src/ESP8266WebServer.h index 156197d60..a4f3bf284 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.h +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.h @@ -55,8 +55,9 @@ typedef struct { String filename; String name; String type; - size_t totalSize; // file size + size_t totalSize; // total size of uploaded file so far size_t currentSize; // size of data currently in buf + size_t contentLength; // size of entire post request, file size + headers and other request data. uint8_t buf[HTTP_UPLOAD_BUFLEN]; } HTTPUpload; diff --git a/libraries/ESP8266WebServer/src/Parsing.cpp b/libraries/ESP8266WebServer/src/Parsing.cpp index 1b70f5b16..9d5ecc012 100644 --- a/libraries/ESP8266WebServer/src/Parsing.cpp +++ b/libraries/ESP8266WebServer/src/Parsing.cpp @@ -468,6 +468,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, const String& boundary, ui _currentUpload->type = argType; _currentUpload->totalSize = 0; _currentUpload->currentSize = 0; + _currentUpload->contentLength = len; #ifdef DEBUG_ESP_HTTP_SERVER DEBUG_OUTPUT.print("Start File: "); DEBUG_OUTPUT.print(_currentUpload->filename);