From b0ba7ad2eeace85ba0ca7727cc01dba81d86ab17 Mon Sep 17 00:00:00 2001 From: Mick Wheeler Date: Fri, 29 Jun 2018 09:25:34 +0100 Subject: [PATCH 1/2] support for concatenation of headers If the server returns several headers of the same key (e.g Set-Cookie) only the last one is returned, causing issues in communicating with some servers where cookies are required. This change concatenates the headers of the same key separated by ";" to alleviate this issue --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 28a3503484..c99df41c66 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -1026,7 +1026,7 @@ int HTTPClient::handleHeaderResponse() for(size_t i = 0; i < _headerKeysCount; i++) { if(_currentHeaders[i].key.equalsIgnoreCase(headerName)) { - _currentHeaders[i].value = headerValue; + _currentHeaders[i].value += headerValue + ";"; break; } } From 387a5144af7852256e52fedb11fad385e3b47a51 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 3 Oct 2018 13:07:00 -0700 Subject: [PATCH 2/2] Use commas and only when needed Change ";" to "," to match the HTTP specs. Add "," on each additional value instead of adding a comma automatically after every value, even single ones. --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index c00004e566..7db0e72c6f 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -1041,8 +1041,13 @@ int HTTPClient::handleHeaderResponse() for(size_t i = 0; i < _headerKeysCount; i++) { if(_currentHeaders[i].key.equalsIgnoreCase(headerName)) { - _currentHeaders[i].value += headerValue + ";"; - break; + if (_currentHeaders[i].value != "") { + // Existing value, append this one with a comma + _currentHeaders[i].value += "," + headerValue; + } else { + _currentHeaders[i].value = headerValue; + } + break; // We found a match, stop looking } } }