Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6f23cd5

Browse filesBrowse files
committed
Make sure that HTTPClient disconnects from the old server if redirecting to new one
Fixes: espressif#4763
1 parent ad4cf14 commit 6f23cd5
Copy full SHA for 6f23cd5

File tree

Expand file treeCollapse file tree

1 file changed

+12
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-5
lines changed

‎libraries/HTTPClient/src/HTTPClient.cpp

Copy file name to clipboardExpand all lines: libraries/HTTPClient/src/HTTPClient.cpp
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,20 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol)
269269

270270
// get port
271271
index = host.indexOf(':');
272+
String the_host;
272273
if(index >= 0) {
273-
_host = host.substring(0, index); // hostname
274+
the_host = host.substring(0, index); // hostname
274275
host.remove(0, (index + 1)); // remove hostname + :
275276
_port = host.toInt(); // get port
276277
} else {
277-
_host = host;
278+
the_host = host;
278279
}
280+
if(_host != the_host && connected()){
281+
log_d("switching host from '%s' to '%s'. disconnecting first", _host.c_str(), the_host.c_str());
282+
_canReuse = false;
283+
disconnect(true);
284+
}
285+
_host = the_host;
279286
_uri = url;
280287
log_d("host: %s port: %d url: %s", _host.c_str(), _port, _uri.c_str());
281288
return true;
@@ -1318,9 +1325,9 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size)
13181325
readBytes = buff_size;
13191326
}
13201327

1321-
// stop if no more reading
1322-
if (readBytes == 0)
1323-
break;
1328+
// stop if no more reading
1329+
if (readBytes == 0)
1330+
break;
13241331

13251332
// read data
13261333
int bytesRead = _client->readBytes(buff, readBytes);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.