1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Merge pull request #565 from me-no-dev/esp8266

Fix plain post slow read
This commit is contained in:
Ivan Grokhotkov 2015-07-20 15:58:16 +03:00
commit e80097dbe6

View File

@ -108,20 +108,26 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
if (!isForm){ if (!isForm){
if (searchStr != "") searchStr += '&'; if (searchStr != "") searchStr += '&';
String bodyLine = client.readStringUntil('\r'); //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';
#ifdef DEBUG #ifdef DEBUG
DEBUG_OUTPUT.print("Plain: "); DEBUG_OUTPUT.print("Plain: ");
DEBUG_OUTPUT.println(bodyLine); DEBUG_OUTPUT.println(plainBuf);
#endif #endif
if(bodyLine.startsWith("{") || bodyLine.startsWith("[") || bodyLine.indexOf('=') == -1){ if(plainBuf[0] == '{' || plainBuf[0] == '[' || strstr(plainBuf, "=") == NULL){
//plain post json or other data //plain post json or other data
searchStr += "plain="; searchStr += "plain=";
searchStr += bodyLine; searchStr += plainBuf;
searchStr += client.readString();
} else { } else {
searchStr += bodyLine; searchStr += plainBuf;
client.readStringUntil('\n');
} }
free(plainBuf);
} }
_parseArguments(searchStr); _parseArguments(searchStr);
if (isForm){ if (isForm){