1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Add writeToPrint to ESP8266HTTPClient (#8056)

This commit is contained in:
Claus Näveke 2021-09-04 19:46:47 +02:00 committed by GitHub
parent d3f16b3177
commit 140d0ffde1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -627,8 +627,18 @@ WiFiClient* HTTPClient::getStreamPtr(void)
*/ */
int HTTPClient::writeToStream(Stream * stream) 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); return returnError(HTTPC_ERROR_NO_STREAM);
} }
@ -645,7 +655,7 @@ int HTTPClient::writeToStream(Stream * stream)
if(_transferEncoding == HTTPC_TE_IDENTITY) { if(_transferEncoding == HTTPC_TE_IDENTITY) {
// len < 0: transfer all of it, with timeout // len < 0: transfer all of it, with timeout
// len >= 0: max:len, with timeout // len >= 0: max:len, with timeout
ret = _client->sendSize(stream, len); ret = _client->sendSize(print, len);
// do we have an error? // do we have an error?
if(_client->getLastSendReport() != Stream::Report::Success) { if(_client->getLastSendReport() != Stream::Report::Success) {
@ -673,7 +683,7 @@ int HTTPClient::writeToStream(Stream * stream)
// data left? // data left?
if(len > 0) { if(len > 0) {
// read len bytes with timeout // read len bytes with timeout
int r = _client->sendSize(stream, len); int r = _client->sendSize(print, len);
if (_client->getLastSendReport() != Stream::Report::Success) if (_client->getLastSendReport() != Stream::Report::Success)
// not all data transferred // not all data transferred
return returnError(StreamReportToHttpClientReport(_client->getLastSendReport())); return returnError(StreamReportToHttpClientReport(_client->getLastSendReport()));

View File

@ -215,6 +215,7 @@ public:
WiFiClient& getStream(void); WiFiClient& getStream(void);
WiFiClient* getStreamPtr(void); WiFiClient* getStreamPtr(void);
int writeToPrint(Print* print);
int writeToStream(Stream* stream); int writeToStream(Stream* stream);
const String& getString(void); const String& getString(void);
static String errorToString(int error); static String errorToString(int error);