@@ -53,9 +53,9 @@ AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer* s, AsyncClient* c)
53
53
, _expectingContinue(false )
54
54
, _contentLength(0 )
55
55
, _parsedLength(0 )
56
- , _headers(LinkedList<AsyncWebHeader *>([](AsyncWebHeader *h){ delete h; }) )
57
- , _params(LinkedList<AsyncWebParameter *>([](AsyncWebParameter *p){ delete p; }) )
58
- , _pathParams(LinkedList<String *>([](String *p){ delete p; }) )
56
+ , _headers({} )
57
+ , _params({} )
58
+ , _pathParams({} )
59
59
, _multiParseState(0 )
60
60
, _boundaryPosition(0 )
61
61
, _itemStartIndex(0 )
@@ -182,7 +182,7 @@ void AsyncWebServerRequest::_removeNotInterestingHeaders(){
182
182
if (_interestingHeaders.containsIgnoreCase (" ANY" )) return ; // nothing to do
183
183
auto prev = decltype (_headers.begin ()) { nullptr };
184
184
for (auto it = _headers.begin (); it != _headers.end (); prev = it, ++it){
185
- if (!_interestingHeaders.containsIgnoreCase ((*it) ->name ().c_str ())){
185
+ if (!_interestingHeaders.containsIgnoreCase (it ->name ().c_str ())){
186
186
_headers.remove (it, prev);
187
187
it = prev;
188
188
}
@@ -231,12 +231,12 @@ void AsyncWebServerRequest::_onDisconnect(){
231
231
_server->_handleDisconnect (this );
232
232
}
233
233
234
- void AsyncWebServerRequest::_addParam (AsyncWebParameter * p){
235
- _params.add (p );
234
+ void AsyncWebServerRequest::_addParam (AsyncWebParameter p){
235
+ _params.add (std::move (p) );
236
236
}
237
237
238
238
void AsyncWebServerRequest::_addPathParam (const char *p){
239
- _pathParams.add (new String (p));
239
+ _pathParams.add (String (p));
240
240
}
241
241
242
242
void AsyncWebServerRequest::_addGetParams (const String& params){
@@ -248,7 +248,7 @@ void AsyncWebServerRequest::_addGetParams(const String& params){
248
248
if (equal < 0 || equal > end) equal = end;
249
249
String name = params.substring (start, equal);
250
250
String value = equal + 1 < end ? params.substring (equal + 1 , end) : String ();
251
- _addParam (new AsyncWebParameter (urlDecode (name), urlDecode (value)));
251
+ _addParam (AsyncWebParameter (urlDecode (name), urlDecode (value)));
252
252
start = end + 1 ;
253
253
}
254
254
}
@@ -316,38 +316,38 @@ bool AsyncWebServerRequest::_parseReqHeader(){
316
316
if (index){
317
317
String name = _temp.substring (0 , index);
318
318
String value = _temp.substring (index + 2 );
319
- if (name.equalsIgnoreCase (" Host" )){
319
+ if (name.equalsIgnoreCase (F ( " Host" ) )){
320
320
_host = value;
321
- } else if (name.equalsIgnoreCase (" Content-Type" )){
321
+ } else if (name.equalsIgnoreCase (F ( " Content-Type" ) )){
322
322
_contentType = value.substring (0 , value.indexOf (' ;' ));
323
- if (value.startsWith (" multipart/" )){
323
+ if (value.startsWith (F ( " multipart/" ) )){
324
324
_boundary = value.substring (value.indexOf (' =' )+1 );
325
325
_boundary.replace (" \" " ," " );
326
326
_isMultipart = true ;
327
327
}
328
- } else if (name.equalsIgnoreCase (" Content-Length" )){
328
+ } else if (name.equalsIgnoreCase (F ( " Content-Length" ) )){
329
329
_contentLength = atoi (value.c_str ());
330
- } else if (name.equalsIgnoreCase (" Expect" ) && value == " 100-continue" ){
330
+ } else if (name.equalsIgnoreCase (F ( " Expect" )) && value == F ( " 100-continue" ) ){
331
331
_expectingContinue = true ;
332
- } else if (name.equalsIgnoreCase (" Authorization" )){
333
- if (value.length () > 5 && value.substring (0 ,5 ).equalsIgnoreCase (" Basic" )){
332
+ } else if (name.equalsIgnoreCase (F ( " Authorization" ) )){
333
+ if (value.length () > 5 && value.substring (0 ,5 ).equalsIgnoreCase (F ( " Basic" ) )){
334
334
_authorization = value.substring (6 );
335
- } else if (value.length () > 6 && value.substring (0 ,6 ).equalsIgnoreCase (" Digest" )){
335
+ } else if (value.length () > 6 && value.substring (0 ,6 ).equalsIgnoreCase (F ( " Digest" ) )){
336
336
_isDigest = true ;
337
337
_authorization = value.substring (7 );
338
338
}
339
339
} else {
340
- if (name.equalsIgnoreCase (" Upgrade" ) && value.equalsIgnoreCase (" websocket" )){
340
+ if (name.equalsIgnoreCase (F ( " Upgrade" )) && value.equalsIgnoreCase (F ( " websocket" ) )){
341
341
// WebSocket request can be uniquely identified by header: [Upgrade: websocket]
342
342
_reqconntype = RCT_WS;
343
343
} else {
344
- if (name.equalsIgnoreCase (" Accept" ) && strContains (value, " text/event-stream" , false )){
344
+ if (name.equalsIgnoreCase (F ( " Accept" )) && strContains (value, F ( " text/event-stream" ) , false )){
345
345
// WebEvent request can be uniquely identified by header: [Accept: text/event-stream]
346
346
_reqconntype = RCT_EVENT;
347
347
}
348
348
}
349
349
}
350
- _headers.add (new AsyncWebHeader (name, value));
350
+ _headers.add (AsyncWebHeader (name, value));
351
351
}
352
352
_temp = String ();
353
353
return true ;
@@ -357,13 +357,13 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data){
357
357
if (data && (char )data != ' &' )
358
358
_temp += (char )data;
359
359
if (!data || (char )data == ' &' || _parsedLength == _contentLength){
360
- String name = " body" ;
360
+ String name = F ( " body" ) ;
361
361
String value = _temp;
362
362
if (!_temp.startsWith (" {" ) && !_temp.startsWith (" [" ) && _temp.indexOf (' =' ) > 0 ){
363
363
name = _temp.substring (0 , _temp.indexOf (' =' ));
364
364
value = _temp.substring (_temp.indexOf (' =' ) + 1 );
365
365
}
366
- _addParam (new AsyncWebParameter (urlDecode (name), urlDecode (value), true ));
366
+ _addParam (AsyncWebParameter (urlDecode (name), urlDecode (value), true ));
367
367
_temp = String ();
368
368
}
369
369
}
@@ -510,13 +510,13 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){
510
510
} else if (_boundaryPosition == _boundary.length () - 1 ){
511
511
_multiParseState = DASH3_OR_RETURN2;
512
512
if (!_itemIsFile){
513
- _addParam (new AsyncWebParameter (_itemName, _itemValue, true ));
513
+ _addParam (AsyncWebParameter (_itemName, _itemValue, true ));
514
514
} else {
515
515
if (_itemSize){
516
516
// check if authenticated before calling the upload
517
517
if (_handler) _handler->handleUpload (this , _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, true );
518
518
_itemBufferIndex = 0 ;
519
- _addParam (new AsyncWebParameter (_itemName, _itemFilename, true , true , _itemSize));
519
+ _addParam (AsyncWebParameter (_itemName, _itemFilename, true , true , _itemSize));
520
520
}
521
521
free (_itemBuffer);
522
522
_itemBuffer = NULL ;
@@ -593,7 +593,7 @@ size_t AsyncWebServerRequest::headers() const{
593
593
594
594
bool AsyncWebServerRequest::hasHeader (const String& name) const {
595
595
for (const auto & h: _headers){
596
- if (h-> name ().equalsIgnoreCase (name)){
596
+ if (h. name ().equalsIgnoreCase (name)){
597
597
return true ;
598
598
}
599
599
}
@@ -621,9 +621,9 @@ bool AsyncWebServerRequest::hasHeader(const __FlashStringHelper * data) const {
621
621
}
622
622
623
623
AsyncWebHeader* AsyncWebServerRequest::getHeader (const String& name) const {
624
- for (const auto & h: _headers){
625
- if (h-> name ().equalsIgnoreCase (name)){
626
- return h;
624
+ for (auto & h: _headers){
625
+ if (h. name ().equalsIgnoreCase (name)){
626
+ return const_cast <AsyncWebHeader*>(&h); // maintain previous interface
627
627
}
628
628
}
629
629
return nullptr ;
@@ -644,8 +644,7 @@ AsyncWebHeader* AsyncWebServerRequest::getHeader(const __FlashStringHelper * dat
644
644
}
645
645
646
646
AsyncWebHeader* AsyncWebServerRequest::getHeader (size_t num) const {
647
- auto header = _headers.nth (num);
648
- return header ? *header : nullptr ;
647
+ return const_cast <AsyncWebHeader*>(_headers.nth (num)); // maintain previous interface
649
648
}
650
649
651
650
size_t AsyncWebServerRequest::params () const {
@@ -654,7 +653,7 @@ size_t AsyncWebServerRequest::params() const {
654
653
655
654
bool AsyncWebServerRequest::hasParam (const String& name, bool post, bool file) const {
656
655
for (const auto & p: _params){
657
- if (p-> name () == name && p-> isPost () == post && p-> isFile () == file){
656
+ if (p. name () == name && p. isPost () == post && p. isFile () == file){
658
657
return true ;
659
658
}
660
659
}
@@ -679,8 +678,8 @@ bool AsyncWebServerRequest::hasParam(const __FlashStringHelper * data, bool post
679
678
680
679
AsyncWebParameter* AsyncWebServerRequest::getParam (const String& name, bool post, bool file) const {
681
680
for (const auto & p: _params){
682
- if (p-> name () == name && p-> isPost () == post && p-> isFile () == file){
683
- return p;
681
+ if (p. name () == name && p. isPost () == post && p. isFile () == file){
682
+ return const_cast <AsyncWebParameter*>(&p); // maintain previous interface
684
683
}
685
684
}
686
685
return nullptr ;
@@ -701,8 +700,7 @@ AsyncWebParameter* AsyncWebServerRequest::getParam(const __FlashStringHelper * d
701
700
}
702
701
703
702
AsyncWebParameter* AsyncWebServerRequest::getParam (size_t num) const {
704
- auto param = _params.nth (num);
705
- return param ? *param : nullptr ;
703
+ return const_cast <AsyncWebParameter*>(_params.nth (num)); // maintain previous interface
706
704
}
707
705
708
706
void AsyncWebServerRequest::addInterestingHeader (const String& name){
@@ -865,7 +863,7 @@ void AsyncWebServerRequest::requestAuthentication(const char * realm, bool isDig
865
863
866
864
bool AsyncWebServerRequest::hasArg (const char * name) const {
867
865
for (const auto & arg: _params){
868
- if (arg-> name () == name){
866
+ if (arg. name () == name){
869
867
return true ;
870
868
}
871
869
}
@@ -889,8 +887,8 @@ bool AsyncWebServerRequest::hasArg(const __FlashStringHelper * data) const {
889
887
890
888
const String& AsyncWebServerRequest::arg (const String& name) const {
891
889
for (const auto & arg: _params){
892
- if (arg-> name () == name){
893
- return arg-> value ();
890
+ if (arg. name () == name){
891
+ return arg. value ();
894
892
}
895
893
}
896
894
return SharedEmptyString;
@@ -921,7 +919,7 @@ const String& AsyncWebServerRequest::argName(size_t i) const {
921
919
922
920
const String& AsyncWebServerRequest::pathArg (size_t i) const {
923
921
auto param = _pathParams.nth (i);
924
- return param ? ** param : SharedEmptyString;
922
+ return param ? *param : SharedEmptyString;
925
923
}
926
924
927
925
const String& AsyncWebServerRequest::header (const char * name) const {
0 commit comments