Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reuse for different URIs in HTTPClient::begin #8466

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,16 @@ bool HTTPClient::begin(WiFiClient &client, const String& url) {
*/
bool HTTPClient::begin(WiFiClient &client, const String& host, uint16_t port, const String& uri, bool https)
{
// Disconnect when reusing HTTPClient to talk to a different host
if (!_host.isEmpty() && _host != host) {
_canReuse = false;
disconnect(true);
}

_client = client.clone();

clear();
clear();

_host = host;
_port = port;
_uri = uri;
Expand Down Expand Up @@ -155,6 +162,8 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
_base64Authorization = base64::encode(auth, false /* doNewLines */);
}

const String oldHost = _host;

// get port
index = host.indexOf(':');
if(index >= 0) {
Expand All @@ -164,6 +173,13 @@ bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol
} else {
_host = host;
}

// Disconnect when reusing HTTPClient to talk to a different host
if (!oldHost.isEmpty() && _host != oldHost) {
_canReuse = false;
disconnect(true);
}

_uri = url;

if ( expectedProtocol != nullptr && _protocol != expectedProtocol) {
Expand Down