make headers work with ignoreCase

Connected to: https://github.com/me-no-dev/ESPAsyncWebServer/issues/64
Eliminates: https://github.com/me-no-dev/ESPAsyncWebServer/pull/70
This commit is contained in:
Me No Dev
2016-09-02 13:52:32 +03:00
parent 85cec3e543
commit b6c9ebd9e6
2 changed files with 22 additions and 13 deletions

View File

@@ -73,6 +73,15 @@ class StringArray {
} }
return false; return false;
} }
bool containsIgnoreCase(String str){
StringArrayItem *it = _items;
while(it != NULL){
if(it->string().equalsIgnoreCase(str))
return true;
it = it->next;
}
return false;
}
String get(size_t index){ String get(size_t index){
size_t i = 0; size_t i = 0;
StringArrayItem *it = _items; StringArrayItem *it = _items;

View File

@@ -267,11 +267,11 @@ bool AsyncWebServerRequest::_parseReqHeader(){
if(index){ if(index){
String name = _temp.substring(0, index); String name = _temp.substring(0, index);
String value = _temp.substring(index + 2); String value = _temp.substring(index + 2);
if(name == "Host"){ if(name.equalsIgnoreCase("Host")){
_host = value; _host = value;
_server->_rewriteRequest(this); _server->_rewriteRequest(this);
_server->_attachHandler(this); _server->_attachHandler(this);
} else if(name == "Content-Type"){ } else if(name.equalsIgnoreCase("Content-Type")){
if (value.startsWith("multipart/")){ if (value.startsWith("multipart/")){
_boundary = value.substring(value.indexOf('=')+1); _boundary = value.substring(value.indexOf('=')+1);
_contentType = value.substring(0, value.indexOf(';')); _contentType = value.substring(0, value.indexOf(';'));
@@ -279,19 +279,19 @@ bool AsyncWebServerRequest::_parseReqHeader(){
} else { } else {
_contentType = value; _contentType = value;
} }
} else if(name == "Content-Length"){ } else if(name.equalsIgnoreCase("Content-Length")){
_contentLength = atoi(value.c_str()); _contentLength = atoi(value.c_str());
} else if(name == "Expect" && value == "100-continue"){ } else if(name.equalsIgnoreCase("Expect") && value == "100-continue"){
_expectingContinue = true; _expectingContinue = true;
} else if(name == "Authorization"){ } else if(name.equalsIgnoreCase("Authorization")){
if(value.startsWith("Basic")){ if(value.length() > 5 && value.substring(0,5).equalsIgnoreCase("Basic")){
_authorization = value.substring(6); _authorization = value.substring(6);
} else if(value.startsWith("Digest")){ } else if(value.length() > 6 && value.substring(0,6).equalsIgnoreCase("Digest")){
_isDigest = true; _isDigest = true;
_authorization = value.substring(7); _authorization = value.substring(7);
} }
} else { } else {
if(_interestingHeaders->contains(name) || _interestingHeaders->contains("ANY")){ if(_interestingHeaders->containsIgnoreCase(name) || _interestingHeaders->containsIgnoreCase("ANY")){
AsyncWebHeader *h = new AsyncWebHeader(name, value); AsyncWebHeader *h = new AsyncWebHeader(name, value);
if(_headers == NULL) if(_headers == NULL)
_headers = h; _headers = h;
@@ -388,10 +388,10 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){
_temp += (char)data; _temp += (char)data;
if((char)data == '\n'){ if((char)data == '\n'){
if(_temp.length()){ if(_temp.length()){
if(_temp.startsWith("Content-Type:")){ if(_temp.length() > 12 && _temp.substring(0, 12).equalsIgnoreCase("Content-Type:")){
_itemType = _temp.substring(14); _itemType = _temp.substring(14);
_itemIsFile = true; _itemIsFile = true;
} else if(_temp.startsWith("Content-Disposition:")){ } else if(_temp.length() > 19 && _temp.substring(0, 19).equalsIgnoreCase("Content-Disposition:")){
_temp = _temp.substring(_temp.indexOf(';') + 2); _temp = _temp.substring(_temp.indexOf(';') + 2);
while(_temp.indexOf(';') > 0){ while(_temp.indexOf(';') > 0){
String name = _temp.substring(0, _temp.indexOf('=')); String name = _temp.substring(0, _temp.indexOf('='));
@@ -551,7 +551,7 @@ int AsyncWebServerRequest::headers(){
bool AsyncWebServerRequest::hasHeader(String name){ bool AsyncWebServerRequest::hasHeader(String name){
AsyncWebHeader* h = _headers; AsyncWebHeader* h = _headers;
while(h != NULL){ while(h != NULL){
if(h->name() == name) if(h->name().equalsIgnoreCase(name))
return true; return true;
h = h->next; h = h->next;
} }
@@ -561,7 +561,7 @@ bool AsyncWebServerRequest::hasHeader(String name){
AsyncWebHeader* AsyncWebServerRequest::getHeader(String name){ AsyncWebHeader* AsyncWebServerRequest::getHeader(String name){
AsyncWebHeader* h = _headers; AsyncWebHeader* h = _headers;
while(h != NULL){ while(h != NULL){
if(h->name() == name) if(h->name().equalsIgnoreCase(name))
return h; return h;
h = h->next; h = h->next;
} }
@@ -620,7 +620,7 @@ AsyncWebParameter* AsyncWebServerRequest::getParam(int num){
} }
void AsyncWebServerRequest::addInterestingHeader(String name){ void AsyncWebServerRequest::addInterestingHeader(String name){
if(!_interestingHeaders->contains(name)) _interestingHeaders->add(name); if(!_interestingHeaders->containsIgnoreCase(name)) _interestingHeaders->add(name);
} }
void AsyncWebServerRequest::send(AsyncWebServerResponse *response){ void AsyncWebServerRequest::send(AsyncWebServerResponse *response){