From d77e6054612e005564f972bcf2a38909b6141a1f Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Tue, 22 Dec 2015 10:43:12 +0100 Subject: [PATCH 1/2] http client allow slow streams for sendRequest fix part of #1274 --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 5cddaf616..cad74cf67 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -354,11 +354,15 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) { if(buff) { // read all data from stream and send it to server - while(connected() && stream->available() && (len > 0 || len == -1)) { + while(connected() && (stream->available() != -1) && (len > 0 || len == -1)) { // get available data size size_t s = stream->available(); + if(len) { + s = ((s > len) ? len : s); + } + if(s) { int c = stream->readBytes(buff, ((s > buff_size) ? buff_size : s)); From 467da7c50f460ddc569fdb779e9dc05fec59ff4b Mon Sep 17 00:00:00 2001 From: Markus Sattler Date: Wed, 23 Dec 2015 12:54:44 +0100 Subject: [PATCH 2/2] better error handling --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 2e611a554..352d76dbf 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -354,7 +354,7 @@ int HTTPClient::sendRequest(const char * type, Stream * stream, size_t size) { if(buff) { // read all data from stream and send it to server - while(connected() && (stream->available() != -1) && (len > 0 || len == -1)) { + while(connected() && (stream->available() > -1) && (len > 0 || len == -1)) { // get available data size size_t s = stream->available();