mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
Web server: wait for data to arrive
Web server: wait for request body until either contentLength is received, or no data is received within 1000ms interval.
This commit is contained in:
commit
3bc3a87efb
@ -138,14 +138,28 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
|||||||
|
|
||||||
if (!isForm){
|
if (!isForm){
|
||||||
if (searchStr != "") searchStr += '&';
|
if (searchStr != "") searchStr += '&';
|
||||||
//some clients send headers first and data after (like we do)
|
char *plainBuf = nullptr;
|
||||||
//give them a chance
|
size_t plainLen = 0;
|
||||||
int tries = 100;//100ms max wait
|
do
|
||||||
while(!client.available() && tries--)delay(1);
|
{
|
||||||
size_t plainLen = client.available();
|
//some clients send headers first and data after (like we do)
|
||||||
char *plainBuf = (char*)malloc(plainLen+1);
|
//give them a chance
|
||||||
client.readBytes(plainBuf, plainLen);
|
int tries = 1000;//1000ms max wait
|
||||||
plainBuf[plainLen] = '\0';
|
size_t newLen;
|
||||||
|
while( !(newLen = client.available()) && tries--) delay(1);
|
||||||
|
if (!newLen) break;
|
||||||
|
plainBuf = (plainBuf == nullptr) ? (char *) malloc(newLen + 1) : (char *) realloc(plainBuf, plainLen + newLen + 1);
|
||||||
|
client.readBytes(&plainBuf[plainLen], newLen);
|
||||||
|
plainLen += newLen;
|
||||||
|
plainBuf[plainLen] = '\0';
|
||||||
|
} while (plainLen < contentLength);
|
||||||
|
/* if data loss, exit */
|
||||||
|
if (plainBuf == nullptr) return false;
|
||||||
|
if (plainLen < contentLength)
|
||||||
|
{
|
||||||
|
free(plainBuf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#ifdef DEBUG_ESP_HTTP_SERVER
|
#ifdef DEBUG_ESP_HTTP_SERVER
|
||||||
DEBUG_OUTPUT.print("Plain: ");
|
DEBUG_OUTPUT.print("Plain: ");
|
||||||
DEBUG_OUTPUT.println(plainBuf);
|
DEBUG_OUTPUT.println(plainBuf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user