Skip to content

Fix support for following redirects added by previous merge #4385

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

Merged
merged 1 commit into from
Oct 14, 2020
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
26 changes: 13 additions & 13 deletions libraries/HTTPClient/src/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,21 +919,19 @@ int HTTPClient::writeToStream(Stream * stream)
*/
String HTTPClient::getString(void)
{
StreamString sstring;

if(_size > 0) {
// try to reserve needed memmory
if(!sstring.reserve((_size + 1))) {
// _size can be -1 when Server sends no Content-Length header
if(_size > 0 || _size == -1) {
StreamString sstring;
// try to reserve needed memory (noop if _size == -1)
if(sstring.reserve((_size + 1))) {
writeToStream(&sstring);
return sstring;
} else {
log_d("not enough memory to reserve a string! need: %d", (_size + 1));
return "";
}
}
else {
return "";
}

writeToStream(&sstring);
return sstring;
return "";
}

/**
Expand Down Expand Up @@ -1441,8 +1439,10 @@ bool HTTPClient::setURL(const String& url)
_port = (_protocol == "https" ? 443 : 80);
}

// disconnect but preserve _client (clear _canReuse so disconnect will close the connection)
_canReuse = false;
// disconnect but preserve _client.
// Also have to keep the connection otherwise it will free some of the memory used by _client
// and will blow up later when trying to do _client->available() or similar
_canReuse = true;
disconnect(true);
return beginInternal(url, _protocol.c_str());
}
Expand Down