From 7de17176403f719400792d4986ff4259fc16f973 Mon Sep 17 00:00:00 2001 From: Jeroen88 Date: Mon, 20 Jan 2020 14:27:51 +0100 Subject: [PATCH] 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. --- libraries/HTTPClient/src/HTTPClient.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index f4b0ae54..187cd6a6 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -910,7 +910,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first, if (replace) { int headerStart = _headers.indexOf(headerLine); - if (headerStart != -1) { + if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) { int headerEnd = _headers.indexOf('\n', headerStart); _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; } } - } void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount)