Skip to content

Commit 8c67523

Browse files
author
gpepe
committed
Update Parsing.cpp
Complete read POST/GET request.
1 parent 2301f29 commit 8c67523

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

libraries/ESP8266WebServer/src/Parsing.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,21 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
138138

139139
if (!isForm){
140140
if (searchStr != "") searchStr += '&';
141-
//some clients send headers first and data after (like we do)
142-
//give them a chance
143-
int tries = 100;//100ms max wait
144-
while(!client.available() && tries--)delay(1);
145-
size_t plainLen = client.available();
146-
char *plainBuf = (char*)malloc(plainLen+1);
147-
client.readBytes(plainBuf, plainLen);
148-
plainBuf[plainLen] = '\0';
141+
char *plainBuf = NULL;
142+
size_t plainLen = 0;
143+
while ( (plainLen == 0) || (plainLen < contentLength))
144+
{
145+
//some clients send headers first and data after (like we do)
146+
//give them a chance
147+
int tries = 100;//100ms max wait
148+
while(!client.available() && tries--)delay(1);
149+
size_t newLen = client.available();
150+
if (!newLen) break;
151+
plainBuf = (plainBuf == NULL) ? (char *) malloc(newLen + 1) : (char *) realloc(plainBuf, plainLen + newLen + 1);
152+
client.readBytes(&plainBuf[plainLen], newLen);
153+
plainLen += newLen;
154+
plainBuf[plainLen] = '\0';
155+
}
149156
#ifdef DEBUG_ESP_HTTP_SERVER
150157
DEBUG_OUTPUT.print("Plain: ");
151158
DEBUG_OUTPUT.println(plainBuf);

0 commit comments

Comments
 (0)