From 2f12c18cc1d168c8ca375caf53775b65c4326ce6 Mon Sep 17 00:00:00 2001
From: chris <chris.smith324@gmail.com>
Date: Wed, 2 Jun 2021 00:45:45 -0400
Subject: [PATCH 1/5] Add support for http proxy to esp8266 http client

---
 .../src/ESP8266HTTPClient.cpp                 | 79 +++++++++++++++++--
 .../ESP8266HTTPClient/src/ESP8266HTTPClient.h |  6 ++
 2 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
index f16167127d..6d73d626e7 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
@@ -858,12 +858,21 @@ bool HTTPClient::connect(void)
 
     _client->setTimeout(_tcpTimeout);
 
-    if(!_client->connect(_host.c_str(), _port)) {
-        DEBUG_HTTPCLIENT("[HTTP-Client] failed connect to %s:%u\n", _host.c_str(), _port);
+    String host = _host;
+    uint16_t port = _port;
+    if (_useProxy)
+    {
+        host = _proxyHost;
+        port = _proxyPort;
+        DEBUG_HTTPCLIENT("[HTTP-Client] using proxy %s:%u\n", host.c_str(), port);
+    }
+
+    if(!_client->connect(host.c_str(), port)) {
+        DEBUG_HTTPCLIENT("[HTTP-Client] failed connect to %s:%u\n", host.c_str(), port);
         return false;
     }
 
-    DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", _host.c_str(), _port);
+    DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", host.c_str(), port);
 
 #ifdef ESP8266
     _client->setNoDelay(true);
@@ -871,6 +880,52 @@ bool HTTPClient::connect(void)
     return connected();
 }
 
+bool HTTPClient::setProxyHost(const String &proxyUrl)
+{
+    String url(proxyUrl);
+
+    DEBUG_HTTPCLIENT("[HTTP-Client][proxy] url: %s\n", url.c_str());
+
+    // check for : (http: or https:
+    int index = url.indexOf(':');
+    if (index < 0) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][proxy] failed to parse protocol\n");
+        return false;
+    }
+
+    _proxyProtocol = url.substring(0, index);
+    url.remove(0, (index + 3)); // remove http:// or https://
+
+    if (_proxyProtocol == "http") {
+        // set default port for 'http'
+        _port = 80;
+    } else if (_proxyProtocol == "https") {
+        // set default port for 'https'
+        _port = 443;
+    } else {
+        DEBUG_HTTPCLIENT("[HTTP-Client][proxy] unsupported protocol: %s\n", _proxyProtocol.c_str());
+        return false;
+    }
+
+    index = url.indexOf('/');
+    String host = url.substring(0, index);
+    url.remove(0, index); // remove host part
+
+    // get port
+    index = host.indexOf(':');
+    if (index >= 0) {
+        _proxyHost = host.substring(0, index); // hostname
+        host.remove(0, (index + 1));           // remove hostname + :
+        _proxyPort = host.toInt();             // get port
+    } else {
+        _proxyHost = host;
+    }
+
+    DEBUG_HTTPCLIENT("[HTTP-Client][proxy] host: %s port: %d\n", _proxyHost.c_str(), _proxyPort);
+    _useProxy = true;
+    return true;
+}
+
 /**
  * sends HTTP request header
  * @param type (GET, POST, ...)
@@ -888,11 +943,23 @@ bool HTTPClient::sendHeader(const char * type)
             _base64Authorization.length() + _host.length() + _userAgent.length() + 128);
     header += type;
     header += ' ';
-    if (_uri.length()) {
-        header += _uri;
+
+    String target;
+    if (_useProxy) {
+        // If using proxy, use full uri in request line (http://foo:123/bar)
+        target = _protocol + F("://") + _host;
+        if (_port != 80 && _port != 443) {
+            target += ':';
+            target += String(_port);
+        }
+        target += _uri.length() ? _uri : F("/");
+    } else if (_uri.length()) {
+        target = _uri;
     } else {
-        header += '/';
+        target = F("/");
     }
+
+    header += target;
     header += F(" HTTP/1.");
 
     if(_useHTTP10) {
diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
index 3605a807f3..76678f55a8 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
@@ -177,6 +177,7 @@ class HTTPClient
     void setAuthorization(const char * user, const char * password);
     void setAuthorization(const char * auth);
     void setTimeout(uint16_t timeout);
+    bool setProxyHost(const String &proxyUrl);
 
     // Redirections
     void setFollowRedirects(followRedirects_t follow);
@@ -247,6 +248,11 @@ class HTTPClient
     String _userAgent;
     String _base64Authorization;
 
+    bool _useProxy = false;
+    String _proxyHost;
+    String _proxyProtocol;
+    uint16_t _proxyPort = 0;
+
     /// Response handling
     RequestArgument* _currentHeaders = nullptr;
     size_t           _headerKeysCount = 0;

From 178495725b3db7bf3f1cf24f6965255b3e556b5c Mon Sep 17 00:00:00 2001
From: chris <chris.smith324@gmail.com>
Date: Wed, 2 Jun 2021 17:58:24 -0400
Subject: [PATCH 2/5] extract uri parsing

---
 .../src/ESP8266HTTPClient.cpp                 | 227 ++++++++----------
 .../ESP8266HTTPClient/src/ESP8266HTTPClient.h |  25 +-
 2 files changed, 119 insertions(+), 133 deletions(-)

diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
index 6d73d626e7..4f83e2fe3e 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
@@ -60,6 +60,12 @@ HTTPClient::~HTTPClient()
     if(_currentHeaders) {
         delete[] _currentHeaders;
     }
+    if (_uri) {
+        delete _uri;
+    }
+    if (_proxyUri) {
+        delete _proxyUri;
+    }
 }
 
 void HTTPClient::clear()
@@ -82,21 +88,13 @@ void HTTPClient::clear()
 bool HTTPClient::begin(WiFiClient &client, const String& url) {
     _client = &client;
 
-    // check for : (http: or https:)
-    int index = url.indexOf(':');
-    if(index < 0) {
-        DEBUG_HTTPCLIENT("[HTTP-Client][begin] failed to parse protocol\n");
-        return false;
-    }
-
-    String protocol = url.substring(0, index);
-    if(protocol != "http" && protocol != "https") {
-        DEBUG_HTTPCLIENT("[HTTP-Client][begin] unknown protocol '%s'\n", protocol.c_str());
+    _uri = parseURI(url);
+    if(_uri == nullptr) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][begin] failed to parse url '%s'\n", url.c_str());
         return false;
     }
 
-    _port = (protocol == "https" ? 443 : 80);
-    return beginInternal(url, protocol.c_str());
+    return true;
 }
 
 
@@ -114,75 +112,15 @@ bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, co
     _client = &client;
 
      clear();
-    _host = host;
-    _port = port;
-    _uri = uri;
-    _protocol = (https ? "https" : "http");
-    return true;
-}
-
-
-bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol)
-{
-    String url(__url);
-
-    DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());
-    clear();
-
-    // check for : (http: or https:
-    int index = url.indexOf(':');
-    if(index < 0) {
-        DEBUG_HTTPCLIENT("[HTTP-Client][begin] failed to parse protocol\n");
-        return false;
-    }
-
-    _protocol = url.substring(0, index);
-    url.remove(0, (index + 3)); // remove http:// or https://
-
-    if (_protocol == "http") {
-        // set default port for 'http'
-        _port = 80;
-    } else if (_protocol == "https") {
-        // set default port for 'https'
-        _port = 443;
-    } else {
-        DEBUG_HTTPCLIENT("[HTTP-Client][begin] unsupported protocol: %s\n", _protocol.c_str());
-        return false;
-    }
-
-    index = url.indexOf('/');
-    String host = url.substring(0, index);
-    url.remove(0, index); // remove host part
-
-    // get Authorization
-    index = host.indexOf('@');
-    if(index >= 0) {
-        // auth info
-        String auth = host.substring(0, index);
-        host.remove(0, index + 1); // remove auth part including @
-        _base64Authorization = base64::encode(auth, false /* doNewLines */);
-    }
-
-    // get port
-    index = host.indexOf(':');
-    if(index >= 0) {
-        _host = host.substring(0, index); // hostname
-        host.remove(0, (index + 1)); // remove hostname + :
-        _port = host.toInt(); // get port
-    } else {
-        _host = host;
-    }
-    _uri = url;
-
-    if ( expectedProtocol != nullptr && _protocol != expectedProtocol) {
-        DEBUG_HTTPCLIENT("[HTTP-Client][begin] unexpected protocol: %s, expected %s\n", _protocol.c_str(), expectedProtocol);
-        return false;
-    }
-    DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s\n", _host.c_str(), _port, _uri.c_str());
+    _uri = new URI{
+        .host = host,
+        .port = port,
+        .protocol = (https ? "https" : "http"),
+        .path = uri,
+    };
     return true;
 }
 
-
 /**
  * end
  * called after the payload is handled
@@ -269,7 +207,7 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
         String auth = user;
         auth += ':';
         auth += password;
-        _base64Authorization = base64::encode(auth, false /* doNewLines */);
+        _uri->base64Authorization = base64::encode(auth, false /* doNewLines */);
     }
 }
 
@@ -280,8 +218,8 @@ void HTTPClient::setAuthorization(const char * user, const char * password)
 void HTTPClient::setAuthorization(const char * auth)
 {
     if(auth) {
-        _base64Authorization = auth;
-        _base64Authorization.replace(String('\n'), emptyString);
+        _uri->base64Authorization = auth;
+        _uri->base64Authorization.replace(String('\n'), emptyString);
     }
 }
 
@@ -305,19 +243,26 @@ bool HTTPClient::setURL(const String& url)
 {
     // if the new location is only a path then only update the URI
     if (url && url[0] == '/') {
-        _uri = url;
+        _uri->path = url;
         clear();
         return true;
     }
 
-    if (!url.startsWith(_protocol + ':')) {
-        DEBUG_HTTPCLIENT("[HTTP-Client][setURL] new URL not the same protocol, expected '%s', URL: '%s'\n", _protocol.c_str(), url.c_str());
+    if (!url.startsWith(_uri->protocol + ":")) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][setURL] new URL not the same protocol, expected '%s', URL: '%s'\n", _uri->protocol.c_str(), url.c_str());
         return false;
     }
     // disconnect but preserve _client (clear _canReuse so disconnect will close the connection)
     _canReuse = false;
     disconnect(true);
-    return beginInternal(url, nullptr);
+
+    _uri = parseURI(url);
+    if(_uri == nullptr) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][setURL] failed to parse url '%s'\n", url.c_str());
+        return false;
+    }
+    
+    return true;
 }
 
 /**
@@ -761,7 +706,7 @@ void HTTPClient::addHeader(const String& name, const String& value, bool first,
     if (!name.equalsIgnoreCase(F("Connection")) &&
         !name.equalsIgnoreCase(F("User-Agent")) &&
         !name.equalsIgnoreCase(F("Host")) &&
-        !(name.equalsIgnoreCase(F("Authorization")) && _base64Authorization.length())) {
+        !(name.equalsIgnoreCase(F("Authorization")) && _uri->base64Authorization.length())) {
 
         String headerLine;
         headerLine.reserve(name.length() + value.length() + 4);
@@ -858,12 +803,12 @@ bool HTTPClient::connect(void)
 
     _client->setTimeout(_tcpTimeout);
 
-    String host = _host;
-    uint16_t port = _port;
+    String host = _uri->host;
+    uint16_t port = _uri->port;
     if (_useProxy)
     {
-        host = _proxyHost;
-        port = _proxyPort;
+        host = _proxyUri->host;
+        port = _proxyUri->port;
         DEBUG_HTTPCLIENT("[HTTP-Client] using proxy %s:%u\n", host.c_str(), port);
     }
 
@@ -880,48 +825,82 @@ bool HTTPClient::connect(void)
     return connected();
 }
 
-bool HTTPClient::setProxyHost(const String &proxyUrl)
-{
-    String url(proxyUrl);
+HTTPClient::URI* HTTPClient::parseURI(const String& __url){
+    String url(__url);
+    URI* uri = new URI{};
 
-    DEBUG_HTTPCLIENT("[HTTP-Client][proxy] url: %s\n", url.c_str());
+    // check for : (http: or https:)
+    int index = url.indexOf(':');
+    if(index < 0) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][parseURI] failed to parse protocol\n");
+        return nullptr;
+    }
+
+    String protocol = url.substring(0, index);
+    if(protocol != "http" && protocol != "https") {
+        DEBUG_HTTPCLIENT("[HTTP-Client][parseURI] unknown protocol '%s'\n", protocol.c_str());
+        return nullptr;
+    }
 
+    uri->port = (protocol == "https" ? 443 : 80);
     // check for : (http: or https:
-    int index = url.indexOf(':');
-    if (index < 0) {
-        DEBUG_HTTPCLIENT("[HTTP-Client][proxy] failed to parse protocol\n");
-        return false;
+    index = url.indexOf(':');
+    if(index < 0) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][parseURI] failed to parse protocol\n");
+        return nullptr;
     }
 
-    _proxyProtocol = url.substring(0, index);
+    uri->protocol = url.substring(0, index);
     url.remove(0, (index + 3)); // remove http:// or https://
 
-    if (_proxyProtocol == "http") {
+    if (uri->protocol == "http") {
         // set default port for 'http'
-        _port = 80;
-    } else if (_proxyProtocol == "https") {
+        uri->port = 80;
+    } else if (uri->protocol == "https") {
         // set default port for 'https'
-        _port = 443;
+        uri->port = 443;
     } else {
-        DEBUG_HTTPCLIENT("[HTTP-Client][proxy] unsupported protocol: %s\n", _proxyProtocol.c_str());
-        return false;
+        DEBUG_HTTPCLIENT("[HTTP-Client][parseURI] unsupported protocol: %s\n", uri->protocol.c_str());
+        return nullptr;
     }
 
     index = url.indexOf('/');
     String host = url.substring(0, index);
     url.remove(0, index); // remove host part
 
+    // get Authorization
+    index = host.indexOf('@');
+    if(index >= 0) {
+        // auth info
+        String auth = host.substring(0, index);
+        host.remove(0, index + 1); // remove auth part including @
+        uri->base64Authorization = base64::encode(auth, false /* doNewLines */);
+    }
+
     // get port
     index = host.indexOf(':');
-    if (index >= 0) {
-        _proxyHost = host.substring(0, index); // hostname
-        host.remove(0, (index + 1));           // remove hostname + :
-        _proxyPort = host.toInt();             // get port
+    if(index >= 0) {
+        uri->host = host.substring(0, index); // hostname
+        host.remove(0, (index + 1)); // remove hostname + :
+        uri->port = host.toInt(); // get port
     } else {
-        _proxyHost = host;
+        uri->host = host;
+    }
+    uri->path = url;
+
+    DEBUG_HTTPCLIENT("[HTTP-Client][parseURI] host: %s port: %d url: %s\n", uri->host.c_str(), uri->port, uri->path.c_str());
+    return uri;
+}
+
+bool HTTPClient::setProxyHost(const String &proxyUrl)
+{
+    _proxyUri = parseURI(proxyUrl);
+    if (_proxyUri == nullptr) {
+        DEBUG_HTTPCLIENT("[HTTP-Client][proxy] failed to parse uri\n");
+        return false;
     }
 
-    DEBUG_HTTPCLIENT("[HTTP-Client][proxy] host: %s port: %d\n", _proxyHost.c_str(), _proxyPort);
+    DEBUG_HTTPCLIENT("[HTTP-Client][proxy] host: %s port: %d\n", _proxyUri->host.c_str(), _proxyUri->port);
     _useProxy = true;
     return true;
 }
@@ -939,22 +918,22 @@ bool HTTPClient::sendHeader(const char * type)
 
     String header;
     // 128: Arbitrarily chosen to have enough buffer space for avoiding internal reallocations
-    header.reserve(_headers.length() + _uri.length() +
-            _base64Authorization.length() + _host.length() + _userAgent.length() + 128);
+    header.reserve(_headers.length() + _uri->path.length() +
+            _uri->base64Authorization.length() + _uri->host.length() + _userAgent.length() + 128);
     header += type;
     header += ' ';
 
     String target;
     if (_useProxy) {
         // If using proxy, use full uri in request line (http://foo:123/bar)
-        target = _protocol + F("://") + _host;
-        if (_port != 80 && _port != 443) {
+        target = _uri->protocol + F("://") + _uri->host;
+        if (_uri->port != 80 && _uri->port != 443) {
             target += ':';
-            target += String(_port);
+            target += String(_uri->port);
         }
-        target += _uri.length() ? _uri : F("/");
-    } else if (_uri.length()) {
-        target = _uri;
+        target += _uri->path.length() ? _uri->path : F("/");
+    } else if (_uri->path.length()) {
+        target = _uri->path;
     } else {
         target = F("/");
     }
@@ -969,11 +948,11 @@ bool HTTPClient::sendHeader(const char * type)
     }
 
     header += F("\r\nHost: ");
-    header += _host;
-    if (_port != 80 && _port != 443)
+    header += _uri->host;
+    if (_uri->port != 80 && _uri->port != 443)
     {
         header += ':';
-        header += String(_port);
+        header += String(_uri->port);
     }
     header += F("\r\nUser-Agent: ");
     header += _userAgent;
@@ -982,9 +961,9 @@ bool HTTPClient::sendHeader(const char * type)
         header += F("\r\nAccept-Encoding: identity;q=1,chunked;q=0.1,*;q=0");
     }
 
-    if (_base64Authorization.length()) {
+    if (_uri->base64Authorization.length()) {
         header += F("\r\nAuthorization: Basic ");
-        header += _base64Authorization;
+        header += _uri->base64Authorization;
     }
 
     header += F("\r\nConnection: ");
diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
index 76678f55a8..0acd08f527 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
@@ -31,6 +31,10 @@
 #include <StreamString.h>
 #include <WiFiClient.h>
 
+
+#define DEBUG_ESP_HTTP_CLIENT 1
+#define DEBUG_ESP_PORT Serial
+
 #ifdef DEBUG_ESP_HTTP_CLIENT
 #ifdef DEBUG_ESP_PORT
 #define DEBUG_HTTPCLIENT(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ## __VA_ARGS__ )
@@ -224,6 +228,14 @@ class HTTPClient
         String value;
     };
 
+    struct URI {
+        String host;
+        uint16_t port = 0;
+        String protocol;
+        String path;
+        String base64Authorization;
+    };
+
     bool beginInternal(const String& url, const char* expectedProtocol);
     void disconnect(bool preserveClient = false);
     void clear();
@@ -232,26 +244,21 @@ class HTTPClient
     bool sendHeader(const char * type);
     int handleHeaderResponse();
     int writeToStreamDataBlock(Stream * stream, int len);
+    static URI* parseURI(const String& url);
 
     WiFiClient* _client;
 
     /// request handling
-    String _host;
-    uint16_t _port = 0;
+    URI* _uri = nullptr;
     bool _reuse = true;
     uint16_t _tcpTimeout = HTTPCLIENT_DEFAULT_TCP_TIMEOUT;
     bool _useHTTP10 = false;
 
-    String _uri;
-    String _protocol;
     String _headers;
     String _userAgent;
-    String _base64Authorization;
-
+    
     bool _useProxy = false;
-    String _proxyHost;
-    String _proxyProtocol;
-    uint16_t _proxyPort = 0;
+    URI* _proxyUri = nullptr;
 
     /// Response handling
     RequestArgument* _currentHeaders = nullptr;

From 891d8ac1b8abc56b4e16a9c5f7360f3d32134c2a Mon Sep 17 00:00:00 2001
From: chris <chris.smith324@gmail.com>
Date: Thu, 3 Jun 2021 15:21:47 -0400
Subject: [PATCH 3/5] reserve string memory

---
 .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp      | 12 +++++++-----
 libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h  |  5 -----
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
index 4f83e2fe3e..9ee5eec7df 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
@@ -805,8 +805,7 @@ bool HTTPClient::connect(void)
 
     String host = _uri->host;
     uint16_t port = _uri->port;
-    if (_useProxy)
-    {
+    if (_proxyUri != nullptr) {
         host = _proxyUri->host;
         port = _proxyUri->port;
         DEBUG_HTTPCLIENT("[HTTP-Client] using proxy %s:%u\n", host.c_str(), port);
@@ -901,7 +900,6 @@ bool HTTPClient::setProxyHost(const String &proxyUrl)
     }
 
     DEBUG_HTTPCLIENT("[HTTP-Client][proxy] host: %s port: %d\n", _proxyUri->host.c_str(), _proxyUri->port);
-    _useProxy = true;
     return true;
 }
 
@@ -924,9 +922,13 @@ bool HTTPClient::sendHeader(const char * type)
     header += ' ';
 
     String target;
-    if (_useProxy) {
+    if (_proxyUri != nullptr) {
+        target.reserve(_uri->protocol.length() + _uri->path.length() +_uri->host.length() + 8);
         // If using proxy, use full uri in request line (http://foo:123/bar)
-        target = _uri->protocol + F("://") + _uri->host;
+        target += _uri->protocol;
+        target += F("://");
+        target += _uri->host;
+
         if (_uri->port != 80 && _uri->port != 443) {
             target += ':';
             target += String(_uri->port);
diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
index 0acd08f527..ed904b87c8 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
@@ -31,10 +31,6 @@
 #include <StreamString.h>
 #include <WiFiClient.h>
 
-
-#define DEBUG_ESP_HTTP_CLIENT 1
-#define DEBUG_ESP_PORT Serial
-
 #ifdef DEBUG_ESP_HTTP_CLIENT
 #ifdef DEBUG_ESP_PORT
 #define DEBUG_HTTPCLIENT(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ## __VA_ARGS__ )
@@ -257,7 +253,6 @@ class HTTPClient
     String _headers;
     String _userAgent;
     
-    bool _useProxy = false;
     URI* _proxyUri = nullptr;
 
     /// Response handling

From 334b3037029628bc8d02bc80cea5c0c91e68dc44 Mon Sep 17 00:00:00 2001
From: chris <chris.smith324@gmail.com>
Date: Thu, 3 Jun 2021 19:57:52 -0400
Subject: [PATCH 4/5] use pointer

---
 .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp      | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
index 9ee5eec7df..9624fbe792 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
@@ -803,20 +803,20 @@ bool HTTPClient::connect(void)
 
     _client->setTimeout(_tcpTimeout);
 
-    String host = _uri->host;
+    String* host = &_uri->host;
     uint16_t port = _uri->port;
     if (_proxyUri != nullptr) {
-        host = _proxyUri->host;
+        host = &_proxyUri->host;
         port = _proxyUri->port;
-        DEBUG_HTTPCLIENT("[HTTP-Client] using proxy %s:%u\n", host.c_str(), port);
+        DEBUG_HTTPCLIENT("[HTTP-Client] using proxy %s:%u\n", host->c_str(), port);
     }
 
-    if(!_client->connect(host.c_str(), port)) {
-        DEBUG_HTTPCLIENT("[HTTP-Client] failed connect to %s:%u\n", host.c_str(), port);
+    if(!_client->connect(host->c_str(), port)) {
+        DEBUG_HTTPCLIENT("[HTTP-Client] failed connect to %s:%u\n", host->c_str(), port);
         return false;
     }
 
-    DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", host.c_str(), port);
+    DEBUG_HTTPCLIENT("[HTTP-Client] connected to %s:%u\n", host->c_str(), port);
 
 #ifdef ESP8266
     _client->setNoDelay(true);

From 1934ef4af4dd16cd11ea15af568b479ef968ea28 Mon Sep 17 00:00:00 2001
From: chris <chris.smith324@gmail.com>
Date: Wed, 9 Jun 2021 23:35:41 -0400
Subject: [PATCH 5/5] Initialize base64authorization with empty string

---
 libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
index 9624fbe792..2e1bf1ef7e 100644
--- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
+++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
@@ -117,6 +117,7 @@ bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, co
         .port = port,
         .protocol = (https ? "https" : "http"),
         .path = uri,
+        .base64Authorization = String(),
     };
     return true;
 }