mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-09-27 14:50:56 +02:00
Fix #837 invalidated iterator when removing items from list
This commit is contained in:
@@ -179,8 +179,17 @@ void AsyncWebServerRequest::_onData(void *buf, size_t len){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AsyncWebServerRequest::_removeNotInterestingHeaders(){
|
void AsyncWebServerRequest::_removeNotInterestingHeaders(){
|
||||||
if (_interestingHeaders.containsIgnoreCase("ANY")) return; // nothing to do
|
if (_interestingHeaders.containsIgnoreCase("ANY")) {
|
||||||
for(const auto& header: _headers){
|
return; // nothing to do
|
||||||
|
}
|
||||||
|
// When removing items from the list, we must increase the iterator first
|
||||||
|
// before removing the current item, otherwise the iterator is invalidated
|
||||||
|
// So, no for(;;) loop can be used, see: https://stackoverflow.com/q/596162
|
||||||
|
auto i_header = _headers.begin();
|
||||||
|
const auto i_end = _headers.end();
|
||||||
|
while (i_header != i_end){
|
||||||
|
const auto header = *i_header;
|
||||||
|
++i_header;
|
||||||
if(!_interestingHeaders.containsIgnoreCase(header->name().c_str())){
|
if(!_interestingHeaders.containsIgnoreCase(header->name().c_str())){
|
||||||
_headers.remove(header);
|
_headers.remove(header);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user