From 0408ae8d12e05cc92e9973d7600ddb7996bae991 Mon Sep 17 00:00:00 2001 From: Wojtek Kaniewski Date: Sat, 4 Dec 2021 14:44:22 +0100 Subject: [PATCH] Don't clear headers on redirect Current implementation clears _headers when request was sent. If the user added custom request headers, they will be lost and the redirected request will not contain them. This commit changes the scope of cleanup so that the headers survive redirects but don't survive connection reuse. --- libraries/HTTPClient/src/HTTPClient.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index c99c633264e..a7bf13e89f5 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -200,6 +200,7 @@ bool HTTPClient::begin(String url, const char* CAcert) end(); } + clear(); _port = 443; if (!beginInternal(url, "https")) { return false; @@ -226,6 +227,7 @@ bool HTTPClient::begin(String url) end(); } + clear(); _port = 80; if (!beginInternal(url, "http")) { return begin(url, (const char*)NULL); @@ -243,7 +245,6 @@ bool HTTPClient::begin(String url) bool HTTPClient::beginInternal(String url, const char* expectedProtocol) { log_v("url: %s", url.c_str()); - clear(); // check for : (http: or https: int index = url.indexOf(':'); @@ -1212,8 +1213,8 @@ int HTTPClient::handleHeaderResponse() return HTTPC_ERROR_NOT_CONNECTED; } - clear(); - + _returnCode = 0; + _size = -1; _canReuse = _reuse; String transferEncoding;