From 47a57e1ec690d0e4fea01a865bc2c5c8adb74b97 Mon Sep 17 00:00:00 2001 From: drderiv Date: Fri, 20 Nov 2020 15:23:43 -0800 Subject: [PATCH] Update to ESP8266HTTPClient.cpp for no Content-Length (#7691) Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header. The added code here fixes that issue. Add logic to writeToStreamDataBlock to only read what's available so as to avoid timeout, and adjust formatting. --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 7ec3ab86f..37cdae0fc 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -725,7 +725,7 @@ 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); // have we an error? @@ -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);