From 8c675236c74189194e3170471e72dc9c2fe107b3 Mon Sep 17 00:00:00 2001 From: gpepe Date: Thu, 7 Apr 2016 22:22:16 +0200 Subject: [PATCH] Update Parsing.cpp Complete read POST/GET request. --- libraries/ESP8266WebServer/src/Parsing.cpp | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/ESP8266WebServer/src/Parsing.cpp b/libraries/ESP8266WebServer/src/Parsing.cpp index 7eac20def..a92ed13d3 100644 --- a/libraries/ESP8266WebServer/src/Parsing.cpp +++ b/libraries/ESP8266WebServer/src/Parsing.cpp @@ -138,14 +138,21 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) { if (!isForm){ if (searchStr != "") searchStr += '&'; - //some clients send headers first and data after (like we do) - //give them a chance - int tries = 100;//100ms max wait - while(!client.available() && tries--)delay(1); - size_t plainLen = client.available(); - char *plainBuf = (char*)malloc(plainLen+1); - client.readBytes(plainBuf, plainLen); - plainBuf[plainLen] = '\0'; + char *plainBuf = NULL; + size_t plainLen = 0; + while ( (plainLen == 0) || (plainLen < contentLength)) + { + //some clients send headers first and data after (like we do) + //give them a chance + int tries = 100;//100ms max wait + while(!client.available() && tries--)delay(1); + size_t newLen = client.available(); + if (!newLen) break; + plainBuf = (plainBuf == NULL) ? (char *) malloc(newLen + 1) : (char *) realloc(plainBuf, plainLen + newLen + 1); + client.readBytes(&plainBuf[plainLen], newLen); + plainLen += newLen; + plainBuf[plainLen] = '\0'; + } #ifdef DEBUG_ESP_HTTP_SERVER DEBUG_OUTPUT.print("Plain: "); DEBUG_OUTPUT.println(plainBuf);