Fix replacing of headers with overlapping names. Fixes issue #3483 (#3487)

If two headers with overlapping names are added while replace == true, like in:
```cpp
http.addHeader("api_token",  "pMXFOLpinQqajaRQJYMeWObg2XYmcX1");
http.addHeader("token", "1234");
```
then replacing went wrong. This is fixed with this PR.
This commit is contained in:
Jeroen88 2020-01-20 14:27:51 +01:00 committed by Me No Dev
parent 8869d39d79
commit 7de1717640

View File

@ -910,7 +910,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
if (replace) { if (replace) {
int headerStart = _headers.indexOf(headerLine); int headerStart = _headers.indexOf(headerLine);
if (headerStart != -1) { if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) {
int headerEnd = _headers.indexOf('\n', headerStart); int headerEnd = _headers.indexOf('\n', headerStart);
_headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1); _headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1);
} }
@ -924,7 +924,6 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
_headers += headerLine; _headers += headerLine;
} }
} }
} }
void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount) void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount)