1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-24 19:42:27 +03:00

ESP8266HTTPClient: fix duplicate Content-Length headers (#1902)

This commit is contained in:
Ivan Grokhotkov
2016-06-03 16:11:44 +08:00
parent d1fc7002c1
commit dd81336b79
5 changed files with 31 additions and 59 deletions

View File

@ -706,19 +706,27 @@ String HTTPClient::errorToString(int error)
* @param value
* @param first
*/
void HTTPClient::addHeader(const String& name, const String& value, bool first)
void HTTPClient::addHeader(const String& name, const String& value, bool first, bool replace)
{
// not allow set of Header handled by code
if(!name.equalsIgnoreCase(F("Connection")) &&
!name.equalsIgnoreCase(F("User-Agent")) &&
!name.equalsIgnoreCase(F("Host")) &&
!(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())){
String headerLine = name;
headerLine += ": ";
if (replace) {
int headerStart = _headers.indexOf(headerLine);
if (headerStart != -1) {
int headerEnd = _headers.indexOf('\n', headerStart);
_headers = _headers.substring(0, headerStart) + _headers.substring(headerEnd + 1);
}
}
headerLine += value;
headerLine += "\r\n";
if(first) {
_headers = headerLine + _headers;
} else {