@@ -154,7 +154,7 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
154
154
_parsedLength += len;
155
155
} else {
156
156
if (_parsedLength == 0 ){
157
- if (_contentType.startsWith (" application/x-www-form-urlencoded" )){
157
+ if (_contentType.startsWith (F ( " application/x-www-form-urlencoded" ) )){
158
158
_isPlainPost = true ;
159
159
} else if (_contentType == FPSTR (CONTENT_TYPE_PLAIN) && __is_param_char (((char *)buf)[0 ])){
160
160
size_t i = 0 ;
@@ -272,19 +272,19 @@ bool AsyncWebServerRequest::_parseReqHead(){
272
272
String u = _temp.substring (m.length ()+1 , index);
273
273
_temp = _temp.substring (index+1 );
274
274
275
- if (m == " GET" ){
275
+ if (m == F ( " GET" ) ){
276
276
_method = HTTP_GET;
277
- } else if (m == " POST" ){
277
+ } else if (m == F ( " POST" ) ){
278
278
_method = HTTP_POST;
279
- } else if (m == " DELETE" ){
279
+ } else if (m == F ( " DELETE" ) ){
280
280
_method = HTTP_DELETE;
281
- } else if (m == " PUT" ){
281
+ } else if (m == F ( " PUT" ) ){
282
282
_method = HTTP_PUT;
283
- } else if (m == " PATCH" ){
283
+ } else if (m == F ( " PATCH" ) ){
284
284
_method = HTTP_PATCH;
285
- } else if (m == " HEAD" ){
285
+ } else if (m == F ( " HEAD" ) ){
286
286
_method = HTTP_HEAD;
287
- } else if (m == " OPTIONS" ){
287
+ } else if (m == F ( " OPTIONS" ) ){
288
288
_method = HTTP_OPTIONS;
289
289
}
290
290
@@ -297,7 +297,7 @@ bool AsyncWebServerRequest::_parseReqHead(){
297
297
_url = urlDecode (u);
298
298
_addGetParams (g);
299
299
300
- if (!_temp.startsWith (" HTTP/1.0" ))
300
+ if (!_temp.startsWith (F ( " HTTP/1.0" ) ))
301
301
_version = 1 ;
302
302
303
303
_temp = String ();
@@ -444,27 +444,27 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){
444
444
_temp += (char )data;
445
445
if ((char )data == ' \n ' ){
446
446
if (_temp.length ()){
447
- if (_temp.length () > 12 && _temp.substring (0 , 12 ).equalsIgnoreCase (" Content-Type" )){
447
+ if (_temp.length () > 12 && _temp.substring (0 , 12 ).equalsIgnoreCase (F ( " Content-Type" ) )){
448
448
_itemType = _temp.substring (14 );
449
449
_itemIsFile = true ;
450
- } else if (_temp.length () > 19 && _temp.substring (0 , 19 ).equalsIgnoreCase (" Content-Disposition" )){
450
+ } else if (_temp.length () > 19 && _temp.substring (0 , 19 ).equalsIgnoreCase (F ( " Content-Disposition" ) )){
451
451
_temp = _temp.substring (_temp.indexOf (' ;' ) + 2 );
452
452
while (_temp.indexOf (' ;' ) > 0 ){
453
453
String name = _temp.substring (0 , _temp.indexOf (' =' ));
454
454
String nameVal = _temp.substring (_temp.indexOf (' =' ) + 2 , _temp.indexOf (' ;' ) - 1 );
455
- if (name == " name" ){
455
+ if (name == F ( " name" ) ){
456
456
_itemName = nameVal;
457
- } else if (name == " filename" ){
457
+ } else if (name == F ( " filename" ) ){
458
458
_itemFilename = nameVal;
459
459
_itemIsFile = true ;
460
460
}
461
461
_temp = _temp.substring (_temp.indexOf (' ;' ) + 2 );
462
462
}
463
463
String name = _temp.substring (0 , _temp.indexOf (' =' ));
464
464
String nameVal = _temp.substring (_temp.indexOf (' =' ) + 2 , _temp.length () - 1 );
465
- if (name == " name" ){
465
+ if (name == F ( " name" ) ){
466
466
_itemName = nameVal;
467
- } else if (name == " filename" ){
467
+ } else if (name == F ( " filename" ) ){
468
468
_itemFilename = nameVal;
469
469
_itemIsFile = true ;
470
470
}
@@ -584,8 +584,10 @@ void AsyncWebServerRequest::_parseLine(){
584
584
_server->_attachHandler (this );
585
585
_removeNotInterestingHeaders ();
586
586
if (_expectingContinue){
587
- const char * response = " HTTP/1.1 100 Continue\r\n\r\n " ;
588
- _client->write (response, os_strlen (response));
587
+ const static char response[] PROGMEM = " HTTP/1.1 100 Continue\r\n\r\n " ;
588
+ char response_stack[sizeof (response)]; // stack, so we can pull it out of flash memory
589
+ memcpy_P (response_stack, response, sizeof (response));
590
+ _client->write (response_stack, os_strlen (response_stack));
589
591
}
590
592
// check handler for authentication
591
593
if (_contentLength){
@@ -858,17 +860,18 @@ bool AsyncWebServerRequest::authenticate(const char * hash){
858
860
859
861
void AsyncWebServerRequest::requestAuthentication (const char * realm, bool isDigest){
860
862
AsyncWebServerResponse * r = beginResponse (401 );
863
+ const static char hdr[] PROGMEM = " WWW-Authenticate" ;
861
864
if (!isDigest && realm == NULL ){
862
- r->addHeader (" WWW-Authenticate " , " Basic realm=\" Login Required\" " );
865
+ r->addHeader (FPSTR (hdr), F ( " Basic realm=\" Login Required\" " ) );
863
866
} else if (!isDigest){
864
- String header = " Basic realm=\" " ;
867
+ String header = F ( " Basic realm=\" " ) ;
865
868
header.concat (realm);
866
869
header.concat (" \" " );
867
- r->addHeader (" WWW-Authenticate " , header);
870
+ r->addHeader (FPSTR (hdr) , header);
868
871
} else {
869
- String header = " Digest " ;
872
+ String header = F ( " Digest " ) ;
870
873
header.concat (requestDigestAuthentication (realm));
871
- r->addHeader (" WWW-Authenticate " , header);
874
+ r->addHeader (FPSTR (hdr) , header);
872
875
}
873
876
send (r);
874
877
}
@@ -988,26 +991,26 @@ String AsyncWebServerRequest::urlDecode(const String& text) const {
988
991
}
989
992
990
993
991
- const char * AsyncWebServerRequest::methodToString () const {
992
- if (_method == HTTP_ANY) return " ANY" ;
993
- else if (_method & HTTP_GET) return " GET" ;
994
- else if (_method & HTTP_POST) return " POST" ;
995
- else if (_method & HTTP_DELETE) return " DELETE" ;
996
- else if (_method & HTTP_PUT) return " PUT" ;
997
- else if (_method & HTTP_PATCH) return " PATCH" ;
998
- else if (_method & HTTP_HEAD) return " HEAD" ;
999
- else if (_method & HTTP_OPTIONS) return " OPTIONS" ;
1000
- return " UNKNOWN" ;
994
+ const __FlashStringHelper * AsyncWebServerRequest::methodToString () const {
995
+ if (_method == HTTP_ANY) return F ( " ANY" ) ;
996
+ else if (_method & HTTP_GET) return F ( " GET" ) ;
997
+ else if (_method & HTTP_POST) return F ( " POST" ) ;
998
+ else if (_method & HTTP_DELETE) return F ( " DELETE" ) ;
999
+ else if (_method & HTTP_PUT) return F ( " PUT" ) ;
1000
+ else if (_method & HTTP_PATCH) return F ( " PATCH" ) ;
1001
+ else if (_method & HTTP_HEAD) return F ( " HEAD" ) ;
1002
+ else if (_method & HTTP_OPTIONS) return F ( " OPTIONS" ) ;
1003
+ return F ( " UNKNOWN" ) ;
1001
1004
}
1002
1005
1003
- const char *AsyncWebServerRequest::requestedConnTypeToString () const {
1006
+ const __FlashStringHelper *AsyncWebServerRequest::requestedConnTypeToString () const {
1004
1007
switch (_reqconntype) {
1005
- case RCT_NOT_USED: return " RCT_NOT_USED" ;
1006
- case RCT_DEFAULT: return " RCT_DEFAULT" ;
1007
- case RCT_HTTP: return " RCT_HTTP" ;
1008
- case RCT_WS: return " RCT_WS" ;
1009
- case RCT_EVENT: return " RCT_EVENT" ;
1010
- default : return " ERROR" ;
1008
+ case RCT_NOT_USED: return F ( " RCT_NOT_USED" ) ;
1009
+ case RCT_DEFAULT: return F ( " RCT_DEFAULT" ) ;
1010
+ case RCT_HTTP: return F ( " RCT_HTTP" ) ;
1011
+ case RCT_WS: return F ( " RCT_WS" ) ;
1012
+ case RCT_EVENT: return F ( " RCT_EVENT" ) ;
1013
+ default : return F ( " ERROR" ) ;
1011
1014
}
1012
1015
}
1013
1016
0 commit comments