1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-09-09 18:40:33 +03:00

Host header support

This commit is contained in:
aalku
2015-08-14 22:30:15 +02:00
committed by Ivan Grokhotkov
parent acc34e2914
commit 5a91c66615
3 changed files with 43 additions and 1 deletions

View File

@@ -94,6 +94,14 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
#ifdef DEBUG
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
DEBUG_OUTPUT.println(headerValue);
#endif
if (headerName == "Content-Type"){
if (headerValue.startsWith("text/plain")){
isForm = false;
@@ -103,7 +111,8 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
} else if (headerName == "Content-Length"){
contentLength = headerValue.toInt();
Serial.printf("Content-Length: %d\r\n", contentLength);
} else if (headerName == "Host"){
_hostHeader = headerValue;
}
}
@@ -137,6 +146,31 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
}
} else {
String headerName;
String headerValue;
//parse headers
while(1){
req = client.readStringUntil('\r');
client.readStringUntil('\n');
if (req == "") break;//no moar headers
int headerDiv = req.indexOf(':');
if (headerDiv == -1){
break;
}
headerName = req.substring(0, headerDiv);
headerValue = req.substring(headerDiv + 2);
#ifdef DEBUG
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
DEBUG_OUTPUT.println(headerValue);
#endif
if (headerName == "Host"){
_hostHeader = headerValue;
}
}
_parseArguments(searchStr);
}
client.flush();