Skip to content
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

Add writeToPrint to ESP8266HTTPClient #8056

Merged
merged 3 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
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
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