mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2026-01-29 09:40:10 +01:00
Disabled request body parsing if the handler does nothing. (#266)
* Disabled request body parsing if the handler does nothing. This will save memory and prevent crashes on large POST requests. Signed-off-by: Alexandr Zarubkin <me21@yandex.ru> * Marked SPIFFSEditor request handler as non-trivial, as it needs to process POST requests. Signed-off-by: Alexandr Zarubkin <me21@yandex.ru>
This commit is contained in:
committed by
Me No Dev
parent
8139925eb9
commit
bf2ffdc51c
@@ -127,12 +127,18 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
|
||||
}
|
||||
}
|
||||
} else if(_parseState == PARSE_REQ_BODY){
|
||||
// A handler should be already attached at this point in _parseLine function.
|
||||
// If handler does nothing (_onRequest is NULL), we don't need to really parse the body.
|
||||
const bool needParse = _handler && !_handler->isRequestHandlerTrivial();
|
||||
if(_isMultipart){
|
||||
size_t i;
|
||||
for(i=0; i<len; i++){
|
||||
_parseMultipartPostByte(((uint8_t*)buf)[i], i == len - 1);
|
||||
_parsedLength++;
|
||||
}
|
||||
if(needParse){
|
||||
size_t i;
|
||||
for(i=0; i<len; i++){
|
||||
_parseMultipartPostByte(((uint8_t*)buf)[i], i == len - 1);
|
||||
_parsedLength++;
|
||||
}
|
||||
} else
|
||||
_parsedLength += len;
|
||||
} else {
|
||||
if(_parsedLength == 0){
|
||||
if(_contentType.startsWith("application/x-www-form-urlencoded")){
|
||||
@@ -149,12 +155,14 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
|
||||
//check if authenticated before calling the body
|
||||
if(_handler) _handler->handleBody(this, (uint8_t*)buf, len, _parsedLength, _contentLength);
|
||||
_parsedLength += len;
|
||||
} else {
|
||||
} else if(needParse) {
|
||||
size_t i;
|
||||
for(i=0; i<len; i++){
|
||||
_parsedLength++;
|
||||
_parsePlainPostChar(((uint8_t*)buf)[i]);
|
||||
}
|
||||
} else {
|
||||
_parsedLength += len;
|
||||
}
|
||||
}
|
||||
if(_parsedLength == _contentLength){
|
||||
|
||||
Reference in New Issue
Block a user