From 5e3e9979aa7560728f6f6e73851115257dc26b21 Mon Sep 17 00:00:00 2001 From: drderiv Date: Tue, 3 Nov 2020 15:50:38 -0800 Subject: [PATCH 1/7] Update to ESP8266HTTPClient.cpp for no Content-Length Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header. The added code here fixes that issue. --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 7ec3ab86f6..76a943e67f 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -732,6 +732,12 @@ int HTTPClient::writeToStream(Stream * stream) if(ret < 0) { return returnError(ret); } + } else if(len == -1 && _client->available() > 0) { + ret = writeToStreamDataBlock(stream, _client->available() > 0); + + // have we an error? + if(ret < 0) { + return returnError(ret); } } else if(_transferEncoding == HTTPC_TE_CHUNKED) { int size = 0; From 5f8466b70971b72b5b3b801855b11ca2f92d8749 Mon Sep 17 00:00:00 2001 From: drderiv Date: Tue, 3 Nov 2020 19:11:10 -0800 Subject: [PATCH 2/7] Update ESP8266HTTPClient.cpp --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 76a943e67f..e182c6765d 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -738,6 +738,7 @@ int HTTPClient::writeToStream(Stream * stream) // have we an error? if(ret < 0) { return returnError(ret); + } } } else if(_transferEncoding == HTTPC_TE_CHUNKED) { int size = 0; From d3f8409d5cf266feb5b56a7547c715f7bf8646e7 Mon Sep 17 00:00:00 2001 From: drderiv Date: Sat, 14 Nov 2020 13:55:35 -0800 Subject: [PATCH 3/7] Update ESP8266HTTPClient.cpp --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index e182c6765d..7ec3ab86f6 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -728,13 +728,6 @@ int HTTPClient::writeToStream(Stream * stream) if(len > 0) { ret = writeToStreamDataBlock(stream, len); - // have we an error? - if(ret < 0) { - return returnError(ret); - } - } else if(len == -1 && _client->available() > 0) { - ret = writeToStreamDataBlock(stream, _client->available() > 0); - // have we an error? if(ret < 0) { return returnError(ret); From 12926f3a6e63d4f925650458b2b5dd4596530f6c Mon Sep 17 00:00:00 2001 From: drderiv Date: Sat, 14 Nov 2020 13:59:06 -0800 Subject: [PATCH 4/7] Update ESP8266HTTPClient.cpp --- .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 7ec3ab86f6..57c44da7da 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -727,12 +727,14 @@ int HTTPClient::writeToStream(Stream * stream) if(_transferEncoding == HTTPC_TE_IDENTITY) { if(len > 0) { ret = writeToStreamDataBlock(stream, len); - - // have we an error? - if(ret < 0) { - return returnError(ret); - } - } + } else if(len == -1 && _client->available() > 0) { + ret = writeToStreamDataBlock(stream, _client->available()); + } + + // have we an error? + if(ret < 0) { + return returnError(ret); + } } else if(_transferEncoding == HTTPC_TE_CHUNKED) { int size = 0; while(1) { From b0188f9aa51b59d539a3552bd34c7a0c06aa1f3b Mon Sep 17 00:00:00 2001 From: drderiv Date: Sat, 14 Nov 2020 14:05:23 -0800 Subject: [PATCH 5/7] Update ESP8266HTTPClient.cpp --- .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 57c44da7da..440f1ab07b 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -728,13 +728,13 @@ int HTTPClient::writeToStream(Stream * stream) if(len > 0) { ret = writeToStreamDataBlock(stream, len); } else if(len == -1 && _client->available() > 0) { - ret = writeToStreamDataBlock(stream, _client->available()); - } + ret = writeToStreamDataBlock(stream, _client->available()); + } - // have we an error? - if(ret < 0) { - return returnError(ret); - } + // have we an error? + if(ret < 0) { + return returnError(ret); + } } else if(_transferEncoding == HTTPC_TE_CHUNKED) { int size = 0; while(1) { From dcefef1f41e00cecc60452cab7827237ebeebfd1 Mon Sep 17 00:00:00 2001 From: drderiv Date: Sun, 15 Nov 2020 08:29:02 -0800 Subject: [PATCH 6/7] Update ESP8266HTTPClient.cpp --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 440f1ab07b..ea448d6baf 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -725,10 +725,8 @@ int HTTPClient::writeToStream(Stream * stream) int ret = 0; if(_transferEncoding == HTTPC_TE_IDENTITY) { - if(len > 0) { + if(len > 0 || len == -1) { ret = writeToStreamDataBlock(stream, len); - } else if(len == -1 && _client->available() > 0) { - ret = writeToStreamDataBlock(stream, _client->available()); } // have we an error? From c18b15b0c5ce441c12c675c2875e944d0c135587 Mon Sep 17 00:00:00 2001 From: drderiv Date: Mon, 16 Nov 2020 14:59:00 -0800 Subject: [PATCH 7/7] Update ESP8266HTTPClient.cpp Add logic to writeToStreamDataBlock to only read what's available so as to avoid timeout, and adjust formatting. --- .../ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index ea448d6baf..37cdae0fc1 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -727,11 +727,11 @@ int HTTPClient::writeToStream(Stream * stream) if(_transferEncoding == HTTPC_TE_IDENTITY) { if(len > 0 || len == -1) { ret = writeToStreamDataBlock(stream, len); - } - // have we an error? - if(ret < 0) { - return returnError(ret); + // have we an error? + if(ret < 0) { + return returnError(ret); + } } } else if(_transferEncoding == HTTPC_TE_CHUNKED) { int size = 0; @@ -1184,6 +1184,12 @@ int HTTPClient::writeToStreamDataBlock(Stream * stream, int size) if(readBytes > buff_size) { readBytes = buff_size; } + + // len == -1 or len > what is available, read only what is available + int av = _client->available(); + if (readBytes < 0 || readBytes > av) { + readBytes = av; + } // read data int bytesRead = _client->readBytes(buff, readBytes);