From 76e322f2e7c726a489e7c5ee2c5e5aa350ee951e Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 26 Apr 2016 15:58:12 +0800 Subject: [PATCH] Fix handling of chunked transfer encoding (#1975) --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 3ce4c16de..28829742a 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -624,6 +624,13 @@ int HTTPClient::writeToStream(Stream * stream) break; } + // read trailing \r\n at the end of the chunk + char buf[2]; + auto trailing_seq_len = _tcp->readBytes((uint8_t*)buf, 2); + if (trailing_seq_len != 2 || buf[0] != '\r' || buf[1] != '\n') { + return returnError(HTTPC_ERROR_READ_TIMEOUT); + } + delay(0); } } else {