Skip to content

Commit 7de1717

Browse files
Jeroen88me-no-dev
Jeroen88
authored andcommitted
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.
1 parent 8869d39 commit 7de1717

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Diff for: libraries/HTTPClient/src/HTTPClient.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
910910

911911
if (replace) {
912912
int headerStart = _headers.indexOf(headerLine);
913-
if (headerStart != -1) {
913+
if (headerStart != -1 && (headerStart == 0 || _headers[headerStart - 1] == '\n')) {
914914
int headerEnd = _headers.indexOf('\n', headerStart);
915915
_headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1);
916916
}
@@ -924,7 +924,6 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
924924
_headers += headerLine;
925925
}
926926
}
927-
928927
}
929928

930929
void HTTPClient::collectHeaders(const char* headerKeys[], const size_t headerKeysCount)

0 commit comments

Comments
 (0)