Skip to content

Commit

Permalink
Add writeToPrint to ESP8266HTTPClient (#8056)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNitek committed Sep 4, 2021
1 parent d3f16b3 commit 140d0ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,18 @@ WiFiClient* HTTPClient::getStreamPtr(void)
*/
int HTTPClient::writeToStream(Stream * stream)
{
return writeToPrint(stream);
}

if(!stream) {
/**
* write all message body / payload to Print
* @param print Print *
* @return bytes written ( negative values are error codes )
*/
int HTTPClient::writeToPrint(Print * print)
{

if(!print) {
return returnError(HTTPC_ERROR_NO_STREAM);
}

Expand All @@ -645,7 +655,7 @@ int HTTPClient::writeToStream(Stream * stream)
if(_transferEncoding == HTTPC_TE_IDENTITY) {
// len < 0: transfer all of it, with timeout
// len >= 0: max:len, with timeout
ret = _client->sendSize(stream, len);
ret = _client->sendSize(print, len);

// do we have an error?
if(_client->getLastSendReport() != Stream::Report::Success) {
Expand Down Expand Up @@ -673,7 +683,7 @@ int HTTPClient::writeToStream(Stream * stream)
// data left?
if(len > 0) {
// read len bytes with timeout
int r = _client->sendSize(stream, len);
int r = _client->sendSize(print, len);
if (_client->getLastSendReport() != Stream::Report::Success)
// not all data transferred
return returnError(StreamReportToHttpClientReport(_client->getLastSendReport()));
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class HTTPClient

WiFiClient& getStream(void);
WiFiClient* getStreamPtr(void);
int writeToPrint(Print* print);
int writeToStream(Stream* stream);
const String& getString(void);
static String errorToString(int error);
Expand Down

0 comments on commit 140d0ff

Please sign in to comment.