@@ -138,14 +138,28 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
138
138
139
139
if (!isForm){
140
140
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 = nullptr ;
142
+ size_t plainLen = 0 ;
143
+ do
144
+ {
145
+ // some clients send headers first and data after (like we do)
146
+ // give them a chance
147
+ int tries = 1000 ;// 1000ms max wait
148
+ size_t newLen;
149
+ while ( !(newLen = client.available ()) && tries--) delay (1 );
150
+ if (!newLen) break ;
151
+ plainBuf = (plainBuf == nullptr ) ? (char *) malloc (newLen + 1 ) : (char *) realloc (plainBuf, plainLen + newLen + 1 );
152
+ client.readBytes (&plainBuf[plainLen], newLen);
153
+ plainLen += newLen;
154
+ plainBuf[plainLen] = ' \0 ' ;
155
+ } while (plainLen < contentLength);
156
+ /* if data loss, exit */
157
+ if (plainBuf == nullptr ) return false ;
158
+ if (plainLen < contentLength)
159
+ {
160
+ free (plainBuf);
161
+ return false ;
162
+ }
149
163
#ifdef DEBUG_ESP_HTTP_SERVER
150
164
DEBUG_OUTPUT.print (" Plain: " );
151
165
DEBUG_OUTPUT.println (plainBuf);
0 commit comments