File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -919,21 +919,19 @@ int HTTPClient::writeToStream(Stream * stream)
919919 */
920920String HTTPClient::getString (void )
921921{
922- StreamString sstring;
923-
924- if (_size > 0 ) {
925- // try to reserve needed memmory
926- if (!sstring.reserve ((_size + 1 ))) {
922+ // _size can be -1 when Server sends no Content-Length header
923+ if (_size > 0 || _size == -1 ) {
924+ StreamString sstring;
925+ // try to reserve needed memory (noop if _size == -1)
926+ if (sstring.reserve ((_size + 1 ))) {
927+ writeToStream (&sstring);
928+ return sstring;
929+ } else {
927930 log_d (" not enough memory to reserve a string! need: %d" , (_size + 1 ));
928- return " " ;
929931 }
930932 }
931- else {
932- return " " ;
933- }
934933
935- writeToStream (&sstring);
936- return sstring;
934+ return " " ;
937935}
938936
939937/* *
@@ -1441,8 +1439,10 @@ bool HTTPClient::setURL(const String& url)
14411439 _port = (_protocol == " https" ? 443 : 80 );
14421440 }
14431441
1444- // disconnect but preserve _client (clear _canReuse so disconnect will close the connection)
1445- _canReuse = false ;
1442+ // disconnect but preserve _client.
1443+ // Also have to keep the connection otherwise it will free some of the memory used by _client
1444+ // and will blow up later when trying to do _client->available() or similar
1445+ _canReuse = true ;
14461446 disconnect (true );
14471447 return beginInternal (url, _protocol.c_str ());
14481448}
You can’t perform that action at this time.
0 commit comments