File tree 1 file changed +13
-13
lines changed
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)
919
919
*/
920
920
String HTTPClient::getString (void )
921
921
{
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 memmory (noop is _size == -1)
926
+ if (sstring.reserve ((_size + 1 ))) {
927
+ writeToStream (&sstring);
928
+ return sstring;
929
+ } else {
927
930
log_d (" not enough memory to reserve a string! need: %d" , (_size + 1 ));
928
- return " " ;
929
931
}
930
932
}
931
- else {
932
- return " " ;
933
- }
934
933
935
- writeToStream (&sstring);
936
- return sstring;
934
+ return " " ;
937
935
}
938
936
939
937
/* *
@@ -1441,8 +1439,10 @@ bool HTTPClient::setURL(const String& url)
1441
1439
_port = (_protocol == " https" ? 443 : 80 );
1442
1440
}
1443
1441
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 ;
1446
1446
disconnect (true );
1447
1447
return beginInternal (url, _protocol.c_str ());
1448
1448
}
You can’t perform that action at this time.
0 commit comments