Reworked timeout + other improvements
This commit is contained in:
parent
1c1c8aa327
commit
85539d0ff2
@ -84,15 +84,22 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
{
|
{
|
||||||
char readChar(0), *parseBuffer(NULL), *parseKey(NULL), *parseValue(NULL);
|
char readChar(0), *parseBuffer(NULL), *parseKey(NULL), *parseValue(NULL);
|
||||||
boolean smallTimeout(false), isKey(true);
|
boolean smallTimeout(false), isKey(true);
|
||||||
|
unsigned int shortTimeout = 100, longTimeout = 5000, activeTimeout = shortTimeout;
|
||||||
|
|
||||||
|
/* Better way to read data
|
||||||
|
char temp[2048];
|
||||||
|
temp[wifiClient->read((uint8_t*)temp,2040)] = '\0';
|
||||||
|
Serial.print(temp);
|
||||||
|
*/
|
||||||
_httpParserState = INIT;
|
_httpParserState = INIT;
|
||||||
_clientTimeout = millis();
|
_clientTimeout = millis();
|
||||||
boolean slashesOrantiSlashesOnly(true);
|
boolean slashesOrAntiSlashesOnly(true);
|
||||||
while(wifiClient->available() || millis() - _clientTimeout < (smallTimeout ? 100 : 5000))
|
while(wifiClient->available() || millis() - _clientTimeout < (smallTimeout ? activeTimeout : 10000))
|
||||||
{
|
{
|
||||||
if(wifiClient->available())
|
if(wifiClient->available())
|
||||||
{
|
{
|
||||||
readChar = (char)wifiClient->read();
|
readChar = (char)wifiClient->read();
|
||||||
|
|
||||||
#ifdef DEBUG_RAW
|
#ifdef DEBUG_RAW
|
||||||
Serial.print(readChar);
|
Serial.print(readChar);
|
||||||
#endif
|
#endif
|
||||||
@ -113,7 +120,6 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
_httpParserState = BODY_SECTION;
|
_httpParserState = BODY_SECTION;
|
||||||
else if(readChar != '\r')
|
else if(readChar != '\r')
|
||||||
_httpParserState = PARAMETER_SECTION;
|
_httpParserState = PARAMETER_SECTION;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case HTTP_VERB_SECTION:
|
case HTTP_VERB_SECTION:
|
||||||
if(readChar >= 65 && readChar <= 90)
|
if(readChar >= 65 && readChar <= 90)
|
||||||
@ -132,6 +138,9 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
_httpParserState = ERROR;
|
_httpParserState = ERROR;
|
||||||
break;
|
break;
|
||||||
case HTTP_RESOURCE_SECTION:
|
case HTTP_RESOURCE_SECTION:
|
||||||
|
if(_httpRequestData.HRM == POST)
|
||||||
|
activeTimeout = longTimeout;
|
||||||
|
|
||||||
if(readChar == '?' )
|
if(readChar == '?' )
|
||||||
{
|
{
|
||||||
free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
|
free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
|
||||||
@ -142,7 +151,7 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
else if(readChar == ' ')
|
else if(readChar == ' ')
|
||||||
{
|
{
|
||||||
free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
|
free(_httpRequestData.httpResource);_httpRequestData.httpResource = NULL;
|
||||||
if(slashesOrantiSlashesOnly)
|
if(slashesOrAntiSlashesOnly)
|
||||||
{
|
{
|
||||||
free(parseBuffer);parseBuffer = NULL;
|
free(parseBuffer);parseBuffer = NULL;
|
||||||
_httpRequestData.httpResource = (char *) malloc(sizeof(char)*2);
|
_httpRequestData.httpResource = (char *) malloc(sizeof(char)*2);
|
||||||
@ -155,7 +164,7 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(readChar != '/' && readChar != '\\') slashesOrantiSlashesOnly = false;
|
if(readChar != '/' && readChar != '\\') slashesOrAntiSlashesOnly = false;
|
||||||
|
|
||||||
parseBuffer = addChar(parseBuffer, readChar);
|
parseBuffer = addChar(parseBuffer, readChar);
|
||||||
_httpParserState = HTTP_RESOURCE_SECTION;
|
_httpParserState = HTTP_RESOURCE_SECTION;
|
||||||
@ -200,7 +209,7 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BODY_SECTION:
|
case BODY_SECTION:
|
||||||
parseBuffer = addChar(parseBuffer, readChar);
|
//parseBuffer = addChar(parseBuffer, readChar);
|
||||||
break;
|
break;
|
||||||
case PARAMETER_SECTION:
|
case PARAMETER_SECTION:
|
||||||
if(readChar == '\n')
|
if(readChar == '\n')
|
||||||
@ -219,14 +228,17 @@ boolean WEBServerManager::parseQuery(WiFiClient *wifiClient)
|
|||||||
_clientTimeout = millis();
|
_clientTimeout = millis();
|
||||||
smallTimeout = true;
|
smallTimeout = true;
|
||||||
}
|
}
|
||||||
|
ESP.wdtFeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parseBuffer != NULL)
|
if(parseBuffer != NULL)
|
||||||
|
{
|
||||||
if(strlen(parseBuffer) > 0)
|
if(strlen(parseBuffer) > 0)
|
||||||
{
|
{
|
||||||
_httpRequestData.httpBody = parseBuffer;
|
_httpRequestData.httpBody = parseBuffer;
|
||||||
parseBuffer = NULL;
|
parseBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.print("HTTP VERB : ");
|
Serial.print("HTTP VERB : ");
|
||||||
|
Loading…
Reference in New Issue
Block a user