1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Add header access using same method as arguments 2

based on @brianensor PR
+sample and some sanity check
This commit is contained in:
luc
2015-10-28 13:58:53 +08:00
parent fbae22f86b
commit ee0b8621f3
4 changed files with 197 additions and 0 deletions

View File

@ -31,6 +31,10 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
client.readStringUntil('\n');
//reset header value
for (int i = 0; i < _headerKeysCount; ++i) {
_currentHeaders[i].value =String();
}
// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
@ -96,6 +100,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
_collectHeader(headerName.c_str(),headerValue.c_str());
#ifdef DEBUG
DEBUG_OUTPUT.print("headerName: ");
@ -161,6 +166,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
_collectHeader(headerName.c_str(),headerValue.c_str());
#ifdef DEBUG
DEBUG_OUTPUT.print("headerName: ");
@ -187,6 +193,15 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
return true;
}
bool ESP8266WebServer::_collectHeader(const char* headerName, const char* headerValue) {
for (size_t i = 0; i < _headerKeysCount; i++) {
if (_currentHeaders[i].key==headerName) {
_currentHeaders[i].value=headerValue;
return true;
}
}
return false;
}
void ESP8266WebServer::_parseArguments(String data) {
#ifdef DEBUG