Skip to content

Commit 4897e00

Browse files
authored
match headers using equalsIgnoreCase (#2474)
Should fix: #2131
1 parent c2414a2 commit 4897e00

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ ESP8266WebServer::ESP8266WebServer(IPAddress addr, int port)
4242
: _server(addr, port)
4343
, _currentMethod(HTTP_ANY)
4444
, _currentVersion(0)
45+
, _currentStatus(HC_NONE)
46+
, _statusChange(0)
4547
, _currentHandler(0)
4648
, _firstHandler(0)
4749
, _lastHandler(0)
@@ -58,6 +60,8 @@ ESP8266WebServer::ESP8266WebServer(int port)
5860
: _server(port)
5961
, _currentMethod(HTTP_ANY)
6062
, _currentVersion(0)
63+
, _currentStatus(HC_NONE)
64+
, _statusChange(0)
6165
, _currentHandler(0)
6266
, _firstHandler(0)
6367
, _lastHandler(0)
@@ -393,7 +397,7 @@ bool ESP8266WebServer::hasArg(String name) {
393397

394398
String ESP8266WebServer::header(String name) {
395399
for (int i = 0; i < _headerKeysCount; ++i) {
396-
if (_currentHeaders[i].key == name)
400+
if (_currentHeaders[i].key.equalsIgnoreCase(name))
397401
return _currentHeaders[i].value;
398402
}
399403
return String();
@@ -428,7 +432,7 @@ int ESP8266WebServer::headers() {
428432

429433
bool ESP8266WebServer::hasHeader(String name) {
430434
for (int i = 0; i < _headerKeysCount; ++i) {
431-
if ((_currentHeaders[i].key == name) && (_currentHeaders[i].value.length() > 0))
435+
if ((_currentHeaders[i].key.equalsIgnoreCase(name)) && (_currentHeaders[i].value.length() > 0))
432436
return true;
433437
}
434438
return false;

libraries/ESP8266WebServer/src/Parsing.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
158158
DEBUG_OUTPUT.println(headerValue);
159159
#endif
160160

161-
if (headerName == "Content-Type"){
161+
if (headerName.equalsIgnoreCase("Content-Type")){
162162
if (headerValue.startsWith("text/plain")){
163163
isForm = false;
164164
} else if (headerValue.startsWith("application/x-www-form-urlencoded")){
@@ -168,9 +168,9 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
168168
boundaryStr = headerValue.substring(headerValue.indexOf('=')+1);
169169
isForm = true;
170170
}
171-
} else if (headerName == "Content-Length"){
171+
} else if (headerName.equalsIgnoreCase("Content-Length")){
172172
contentLength = headerValue.toInt();
173-
} else if (headerName == "Host"){
173+
} else if (headerName.equalsIgnoreCase("Host")){
174174
_hostHeader = headerValue;
175175
}
176176
}
@@ -237,7 +237,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
237237
DEBUG_OUTPUT.println(headerValue);
238238
#endif
239239

240-
if (headerName == "Host"){
240+
if (headerName.equalsIgnoreCase("Host")){
241241
_hostHeader = headerValue;
242242
}
243243
}
@@ -257,7 +257,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
257257

258258
bool ESP8266WebServer::_collectHeader(const char* headerName, const char* headerValue) {
259259
for (int i = 0; i < _headerKeysCount; i++) {
260-
if (_currentHeaders[i].key==headerName) {
260+
if (_currentHeaders[i].key.equalsIgnoreCase(headerName)) {
261261
_currentHeaders[i].value=headerValue;
262262
return true;
263263
}
@@ -389,7 +389,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
389389

390390
line = client.readStringUntil('\r');
391391
client.readStringUntil('\n');
392-
if (line.startsWith("Content-Disposition")){
392+
if (line.length() > 19 && line.substring(0, 19).equalsIgnoreCase("Content-Disposition")){
393393
int nameStart = line.indexOf('=');
394394
if (nameStart != -1){
395395
argName = line.substring(nameStart+2);
@@ -414,7 +414,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
414414
argType = "text/plain";
415415
line = client.readStringUntil('\r');
416416
client.readStringUntil('\n');
417-
if (line.startsWith("Content-Type")){
417+
if (line.length() > 12 && line.substring(0, 12).equalsIgnoreCase("Content-Type")){
418418
argType = line.substring(line.indexOf(':')+2);
419419
//skip next line
420420
client.readStringUntil('\r');

0 commit comments

Comments
 (0)